页面引用了两个样式表:

<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. .Net在线编辑器:KindEditor及CkEditor+CkFinder配置说明

    Net在线编辑器:KindEditor及CkEditor+CkFinder配置说明 一.KindEditor(免费) KindEditor是一套开源的HTML可视化编辑器,主要用于让用户在网站上获得所 ...

  2. 关于这个 SDK.InvalidRegionId : Can not find endpoint to access

    String product = "Dysmsapi";//短信API产品名称(短信产品名固定,无需修改)       TM 调试了半天,一直报错.原来是因为我改了上面的 Dysm ...

  3. 玩转X-CTR100 l STM32F4 l ESP8266串口WIFI模块

    我造轮子,你造车,创客一起造起来!更多塔克创新资讯[塔克社区 www.xtark.cn ][塔克博客 www.cnblogs.com/xtark/ ]- ESP8266是一款非常火的WIFI模块,性价 ...

  4. MyEclipse持续性开发教程:用JPA和Spring管理数据(三)

    MyEclipse红运年货节 在线购买低至69折!火爆开抢>> [MyEclipse最新版下载] 本教程介绍了MyEclipse中的一些基于JPA / Spring的功能.有关设置JPA项 ...

  5. ZedGraph实时曲线实例

    2010-10-17 11:23:58| 分类: ASP.NET |举报|字号 订阅public partial class FrmMain : Form { // 起始时间以毫秒为单位 int ti ...

  6. CSS3之border-image

    先上效果图,类似于IPHONE手机左上角的返回按钮样式,如果是在CSS2那么就要做一张背景图片扩展就没那么灵活了,CSS3内就不需要了,CSS3样式挺强大方便的. 源图片: 样式: .banner { ...

  7. NBUT 1218 You are my brother 2010辽宁省赛

    Time limit 1000 ms Memory limit 131072 kB Little A gets to know a new friend, Little B, recently. On ...

  8. 转:Canvas标签的width和height以及style.width和style.height的区别

    转自:http://www.cnblogs.com/artwl/archive/2012/02/28/2372042.html 作者:Artwl 背景 今天在博问中看到一个问题:用canvas 的 l ...

  9. HDU 4585

    http://acm.hdu.edu.cn/showproblem.php?pid=4585 从原来的人中找出战斗数值最接近的,输出他们两人的序号 要在logn的复杂度完成查找,我用的是set,当然用 ...

  10. Python入门——第一个Python程序

    1.1 Hello Python书写步骤 步骤一:新建文本文档文件,修改名称为hello.py 步骤二:使用记事本打开文件,书写程序内容如下: print("hello python&quo ...