页面引用了两个样式表:

<link href="css/mui.min.css" rel="stylesheet" />
<link href="css/new_menu.css" rel="stylesheet" />
//获取样式表对象
function getStyleSheet(){ //获取样式表对象,此处为new_menu.css样式文件
var styleSheets = document.styleSheets; for(var i=0; i<styleSheets.length;i++){ var sheet=styleSheets[i];//console.log(sheet.href); if(sheet.href==undefined || sheet.href==null){
continue;
} if(sheet.href.indexOf('new_menu')>0){ styleSheet=sheet;//console.log(i);
break;
}
}
//console.log(styleSheet);
}
for(var item in rule){
console.log(item);
}
输出样式规则对象属性
cssRules at new_touchMove.html:204
name at new_touchMove.html:204
parentRule at new_touchMove.html:204
parentStyleSheet at new_touchMove.html:204
cssText at new_touchMove.html:204
type at new_touchMove.html:204
insertRule at new_touchMove.html:204
deleteRule at new_touchMove.html:204
findRule at new_touchMove.html:204
UNKNOWN_RULE at new_touchMove.html:204
STYLE_RULE at new_touchMove.html:204
CHARSET_RULE at new_touchMove.html:204
IMPORT_RULE at new_touchMove.html:204
MEDIA_RULE at new_touchMove.html:204
FONT_FACE_RULE at new_touchMove.html:204
PAGE_RULE at new_touchMove.html:204
WEBKIT_KEYFRAMES_RULE at new_touchMove.html:204
WEBKIT_KEYFRAME_RULE at new_touchMove.html:204
SUPPORTS_RULE at new_touchMove.html:204
WEBKIT_FILTER_RULE at new_touchMove.html:204
HOST_RULE at new_touchMove.html:204
//动态创建css规则
function createRule(menuCss,i,x,y,offsetX,offsetY,cssIndex){ var offset_x=x-offsetX;
var offset_y=y-offsetY; var btn ='.btn'+i;
var btnCss='left: '+offset_x+'px; top: '+offset_y+'px; animation: btn'+i+' 300ms;-webkit-animation: btn'+i+' 300ms;-moz-animation: btn'+i+' 300ms;-o-animation: btn'+i+' 300ms;';
menuCss.insertRule(btn+'{'+btnCss+'}',cssIndex); var webkitKeyframes ='@-webkit-keyframes btn'+i;
var webkitKeyframesCss='0%{ left: '+x+'px; top: '+y+'px; } 100%{ left: '+offset_x+'px; top: '+offset_y+'px;}';
menuCss.insertRule(webkitKeyframes+'{'+webkitKeyframesCss+'}',cssIndex+1); var keyFrames ='@keyframes btn'+i;
var keyFramesCss='0%{ left: '+x+'px; top: '+y+'px; } 100%{ left: '+offset_x+'px; top: '+offset_y+'px;}';
menuCss.insertRule(keyFrames+'{'+keyFramesCss+'}',cssIndex+2); var mozKeyframes ='@-moz-keyframes btn'+i;
var mozKeyframesCss='0%{ left: '+x+'px; top: '+y+'px; } 100%{ left: '+offset_x+'px; top: '+offset_y+'px;}';
menuCss.insertRule(mozKeyframes+'{'+mozKeyframesCss+'}',cssIndex+3);
}
//删除css规则
function delRules(styleSheet){ for(var i=21; i<styleSheet.cssRules.length; i++){
var rule = styleSheet.cssRules[i]; //rule.type == CSSRule.KEYFRAMES_RULE || rule.type == CSSRule.WEBKIT_KEYFRAMES_RULE || rule.type == CSSRule.MOZ_KEYFRAMES_RULE
if(rule.type == 1 || rule.type == 7){
//根据规则索引删除规则
styleSheet.deleteRule(i);
}
}
}

动态修改css 规则的更多相关文章

  1. ASP.NET中直接用C# 动态修改CSS样式

    ASP.NET中直接用C# 动态修改CSS样式  wonsoft (wonsoft@163.com) 使用JavaScript控制CSS样式有点麻烦,还是觉得直接使用C#操作更方便快捷,本文通过两个B ...

  2. JavaScript动态修改CSS

    链接:https://www.cnblogs.com/aademeng/articles/6279060.html 在很多情况下,都需要对网页上元素的样式进行动态的修改.在JavaScript中提供几 ...

  3. javascript 动态修改css样式方法汇总(四种方法)

    在很多情况下,都需要对网页上元素的样式进行动态的修改.在JavaScript中提供几种方式动态的修改样式,下面将介绍方法的使用.效果.以及缺陷. 1.使用obj.className来修改样式表的类名. ...

  4. JS笔记一:动态修改css样式

    ---恢复内容开始--- 最近在学习CSS/JS的样式,两个合学习一起学习,加深JS的书写和了解. 一.通过Javasript修改图片大小 通过函数来传递图片id,height,width,使用doc ...

  5. 动态修改css文件中,具体的class中的个别属性值。

    function setStyleSheetObjCssClassProperty(pStyleSheetObj, pSelectorText, pProperty, pValue) { var pS ...

  6. 微信小程序通过js动态修改css样式的方法(交流QQ群:604788754)

    WXML <view class="page" style="background-color:{{pageBackgroundColor}}" > ...

  7. javascript 动态修改css样式

    方法一:改变外联css文件,这里不讲这个. 方法二:通过改变claaName来改变样式,语法: obj.className = "style2"; //或者 obj.setAttr ...

  8. 关于在jquery动态修改css,html中,mouseenter,mouseleave,click等方法失效的处理

  9. vue 动态修改 css

    <div v-for="i in resultDate" v-if="i.ProjectId>='4'" @click=EveyTesttInfo( ...

随机推荐

  1. bzoj3105

    题解: 一道博弈论 题目要求取得最少,那么就是留下的最多 把石子从大到小排序 从打的开始刘 如果可以留,那么就留下了 如果留下了与前面留下来的异或后不为0,那么就可以留 代码: #include< ...

  2. selenium(一)简介,安装,配置,测试。

    简介: Selenium也是一个用于Web应用程序测试的工具.Selenium测试直接运行在浏览器中,就像真正的用户在操作一样.支持的浏览器包括IE.Mozilla Firefox.Mozilla S ...

  3. 深入理解Linux网络技术内幕——Notification内核通知表链

    为什么要有内核通知表链:     Linux由多个相互依赖的子系统组成.其中一些子系统可能需要对其他子系统的一些事件感兴趣.这样子系统之间需要一些通信机制来实现这一功能.     在接触Notific ...

  4. L243 词汇题2009

    The applications of genetic engineering are abundant (plentiful) and choosing one appropriate for th ...

  5. require('nw.gui') 失效问题

    // gui = global.window.nwDispatcher.requireNwGui() --original // gui = window.require('nw.gui') gui ...

  6. SecureCRT来上传和下载文件

    引用:https://www.cnblogs.com/zhengyihan1216/p/6260667.html Linux--用SecureCRT来上传和下载文件 SecureCRT下的文件传输协议 ...

  7. 第三课 操作系统开发之x86模拟环境搭建

    前面我们讲解了主引导程序的加载过程,并且制作了虚拟软盘a.img,最终这个主引导程序也在机器中成功运行了,但是实际开发的时候,并不会如此简单,免不了调试过程,如果还像上一节中直接将软盘放到机器中去加载 ...

  8. Android_ndk_jni_hello-jni_hacking

    /*************************************************************************** * Android_ndk_jni_hello ...

  9. URAL - 1003:Parity (带权并查集&2-sat)

    Now and then you play the following game with your friend. Your friend writes down a sequence consis ...

  10. C# 处理DateTime算法,取某月第1天及最后一天

    代码如下所示: /// <summary> /// 取得某月的第一天 /// </summary> /// <param name="datetime" ...