用JavaScript操作CSS滤镜实现最近新闻旁边的“new”
2011-03-04 11:45
246 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>用JavaScript操作CSS滤镜实现最近新闻旁边的“new”</title> <style type="text/css"> .abc span { display: inline-block; /*IE中只有块元素滤镜才有效*/ color: #fff; filter: glow(color=red,strength=2); width: 50px; font-weight:bold; } .a { width: 100px; } </style> <script type="text/javascript"> var tempStrength = 1; var idirection = 1; var timerID = null; function MyTimer() { var ss = document.styleSheets[0]; //获得该文档的样式表,数组元素类型是CSSStyleSheet //FF是cssRules,IE是rules。rules代表样式表中的规则,类型是CSSRule var rules = ss.cssRules ? ss.cssRules : ss.rules; //某个规则不能通过这样访问rules[".a"],需要做循环拿出选择器的名称然后做比较进行筛选 for (var i = 0; i < rules.length; i++) { var rule = rules[i]; if (!rule.selectorText)//css选择器的名称 continue; if (rule.selectorText.toLowerCase() == ".abc span") { //内嵌样式的filter属性的类型是对象 //tempStrength = document.getElementById("span1").filters["glow"]; //rule.style.color = "blue"; if (idirection == 1) { tempStrength++; } else { tempStrength--; } if (tempStrength == 3 && idirection == 1) { idirection = -1; } if (tempStrength == 2 && idirection == -1) { idirection = 1; } //内联样式的filter属性的类型是String rule.style.filter = "glow(color=red,strength=" + tempStrength + ")"; timerID = setTimeout("MyTimer()", 1000); } } // tempStrength = document.getElementById("span1").filters["glow"].strength; // if (idirection == 1) { // tempStrength++; // } else { // tempStrength--; // } // if (tempStrength == 3 && idirection == 1) { // idirection = -1; // } // if (tempStrength == 2 && idirection == -1) { // idirection = 1; // } // document.all.span1.filters["glow"].strength = tempStrength; // timerID = setTimeout("MyTimer()", 500); // timerRunning = true; } </script> </head> <body onload="MyTimer()"> <ul class="abc"> <li>1<span id="span1">new</span></li> <li>2<span>new</span></li> <li>3<span>new</span></li> <li>4<span>new</span></li> </ul> </body> </html>
相关文章推荐
- JavaScript及jquey实现多个数组的合并操作
- JavaScript操作Cookie实现“历史搜索”
- 使用new实现realloc操作
- 57-005-3 bootstrap实现一个简单的项目案例--新闻操作(基于jsp无刷新异步操作)
- javascript实现操作cookie实现的可记忆菜单
- JavaScript简洁继承机制实现(不使用prototype和new)
- javascript操作word实现替换功能
- JavaScript基于DOM操作实现简单的数学运算功能示例
- Javascript 对象操作运算符 5.8.1 new运算符
- 关于在SharePoint 2013(2010)中Javascript如何实现批量批准的自定义操作功能?
- JavaScript实现多叉树的递归遍历和非递归遍历算法操作示例
- Javascript实现滚动图片新闻
- javascript 操作Word和Excel的实现代码
- 15.odoo入门——工作遇到的odoo的一些细节和javascript实现数据库操作后跳转页面
- JavaScript(1):Js实现web页面一段时间没操作,退出或关闭页面
- javascript 中的 new 操作
- JavaScript实现对P标签的操作
- 新闻发布项目——数据实现类(newsTbDaoImpl)
- 26、Selenium + Python 实现 UI 自动化测试-调用 JavaScript 操作滚动条