In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
今天小编给大家分享一下如何用JavaScript和jQuery制作光棒效果的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。
使用javaScript制作光棒效果
--首先是javaScript
$(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"; } } });
两种方式相比相对来说:.cssText比较简便
使用jQuery制作光棒效果
$(function () { $("li").hover(function () { //这里调用复合事件 模拟鼠标悬停事件 $(this).css({"background-color": "red","font-size":"50px"}); }, function () { $(this).css({ "background-color": "", "font-size": "20px" }); //直接追加CSS样式 } ); });
相对于javaScript jQuer代码更灵活,简便一些,(jQuery中有自动遍历效果,所有省了循环)
以上就是"如何用JavaScript和jQuery制作光棒效果"这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注行业资讯频道。
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.