页面引用了两个样式表:

<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. jenkins的应用与搭建

    实验条件2个服务器, git服务器 ip地址:192.168.200.151 Jenkins服务器 ip地址:192.168.200.132 操作系统:centos7.5 [root@git ~]# ...

  2. bzoj1602

    题解: 简单lca 然而我调了半小时QAQ lca的时候要判断0 代码: #include<bits/stdc++.h> using namespace std; ; ][N],num[N ...

  3. DevExpress WPF入门指南:跟随 Items Source 向导完成数据绑定

    Items Source Wizard Items Source Configuration Wizard允许在设计时执行数据绑定.跟随这个向导可以自动生成XAML数据绑定代码. 下面就来展示下如何使 ...

  4. LibSVM文件转换为csv格式

    Spark MLlib 的官方例子里面提供的数据大部分是 libsvm 格式的.这其实是一种非常蛋疼的文件格式,和常见的二维表格形式相去甚远,下图是里面的一个例子: libsvm 文件的基本格式如下: ...

  5. Unity5.X 新版AssetBundle使用方案及策略

    1.概览 Unity3D 5.0版本之后的AssetBundle机制和之前的4.x版本已经发生了很大的变化,一些曾经常用的流程已经不再使用,甚至一些老的API已经被新的API所取代. 因此,本文的主要 ...

  6. 使用Arduino模块实施无线信号的重放攻击

    无线电已经存在使用了很长一段时间,在这很长的一段时间里诞生了一个名叫火腿族的集体(小编:嗯 对 就是整天吃火腿的那些人^_^  CQ CQ ).无线电和互联网一样:同样存在一些安全隐患,比如:在无线信 ...

  7. Tesseract-OCR 训练教程(一)

    实际应用中[font]替换为你自己的字体名,比如newfont.hehe等 1.根据tif生成box文件(位置宽高等信息)tesseract [font].font.exp0.tif [font].f ...

  8. Redis学习第三课:Redis Hash类型及操作

    Redis hash是一个string类型的field和value的映射表.它的添加.删除操作都是O(1)(平均).hash特别适用于存储对象.相较于对象的每个字段存在单个string类型.将一个对象 ...

  9. UIView.animateWithDuration 没有动画过渡效果直接跳到最后

    当我在viewDidLoad()方法内添加以下代码的时候发现程序运行时不会有动画过度效果,而是直接跳到了最后. let x = (self.view.bounds.size.width - 268) ...

  10. Spring MVC - 拦截器实现 和 用户登陆例子

    1.拦截器 SpringMvc中的拦截器实现了HandlerInterceptor接口,通常使用与身份认证,授权和校验,模板视图,统一处理等: public class HanderIntercept ...