前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【前端开发系列】—— 通过鼠标浮动改变样式

【前端开发系列】—— 通过鼠标浮动改变样式

作者头像
用户1154259
发布2018-01-18 12:17:51
7930
发布2018-01-18 12:17:51
举报

这个简单的demo,可以应用到很多地方。比如导航鼠标移动到上方时,可以改变样式,或者触发下拉框,等等。很有意思

代码语言:javascript
复制
 1 <html>
 2 <head>
 3 <style type="text/css">
 4     .red {
 5         color:red;
 6         font-size: 32;
 7         font-style: italic;
 8     }
 9     .blue {
10         color: blue;
11         font-size: 25;
12     }
13     .black {
14         color: black;
15         font-size: 16;
16     }
17 </style>
18 
19 <script type="text/javascript">
20     function color(e){
21         switch(e.srcElement.id){
22             case "first":
23                 document.getElementById("first").className = "red";
24                 break;
25             case "second":
26                 document.getElementById("second").className = "blue";
27                 break;
28         }
29     }
30     function clearText(e){
31         switch(e.srcElement.id){
32             case "first":
33                 document.getElementById("first").className = "black";
34                 break;
35             case "second":
36                 document.getElementById("second").className = "black";
37                 break;
38         }
39     }
40 </script>
41 </head>
42 <body>
43     <div id="first" onMouseOver="color(event);" onMouseOut="clearText(event);"> hello1 </div>
44     <div id="second" onMouseOver="color(event);" onMouseOut="clearText(event);"> hello2 </div>
45 </body>
46 </html>

样例展示

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2014-09-23 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 样例展示
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档