JavaScript和jQuery制作光棒效果

JavaScript和jQuery制作光棒效果

使用javaScript与jQuery添加CSS样式的区别和步骤

使用javaScript制作光棒效果

--首先是javaScript

<script>    $(function () {      var lis = document.getElementsByTagName("li"); //定义DOM变量接受标签为li的元素      for (var i = 0; i < lis.length;i++){              lis[i].onmouseover = function () {          //方式一          //this.style.backGround = "pink";   //1,注意这里只能使用this方法作为for循环当前遍历项          //this.style.fontSize = "50px";   //2,同样style之后的追加的样式命名只能用骆驼命名法          //方式二          this.style.cssText = "background-color:red;font-size:50px";        };        lis[i].onmouseout = function () {          //方式一          //this.style.background = "";          //this.style.fontSize = "20px";          //方式二          this.style.cssText = "background-color:;font-size:20px";        }      }    });  </script>

两种方式相比相对来说:.cssText比较简便

使用jQuery制作光棒效果

 <script>    $(function () {      $("li").hover(function () {                  //这里调用复合事件 模拟鼠标悬停事件        $(this).css({"background-color": "red","font-size":"50px"});      },      function () {        $(this).css({ "background-color": "", "font-size": "20px" });  //直接追加CSS样式      }      );    });  </script>

相对于javaScript  jQuer代码更灵活,简便一些,(jQuery中有自动遍历效果,所有省了循环)

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!

tag:效果电脑软件Javascriptjquery

相关内容