码迷,mamicode.com
首页 > Web开发 > 详细

js常用特效——选项卡效果

时间:2017-07-08 15:15:50      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:.class   size   block   poi   text   one   abs   asc   char   

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="UTF-8">
 5         <title></title>
 6         <style type="text/css">
 7             *{
 8                 margin: 0px;
 9                 padding: 0px;
10                 list-style: none;
11             }
12             ol>li{
13                 width: 50px;
14                 height: 30px;
15                 text-align: center;
16                 line-height: 30px;
17                 color: red;
18                 background: #e0e0e0;
19                 display: inline-block;
20                 margin-right: 3px;
21                 font-weight: bold;
22                 cursor: pointer;
23             }
24             ul{
25                 margin: 100px 0px 0px 100px;
26                 position: relative;
27             }
28             ul>li{
29                 width: 300px;
30                 height: 200px;
31                 font-size: 40px;
32                 color: #fff;
33                 position: absolute;
34                 top: 0px;
35                 left: 0px;
36                 display: none;
37             }
38             ul>li:nth-of-type(1){
39                 background: #ff6700;
40             }
41             ul>li:nth-of-type(2){
42                 background: green;
43             }
44             ul>li:nth-of-type(3){
45                 background: blue;
46             }
47             .show{
48                 display: block;
49             }
50             .bg{
51                 background: #FF6700;
52                 color: white;
53             }
54         </style>
55     </head>
56     <body>
57         <ol id="ol">
58             <li>1</li>
59             <li>2</li>
60             <li>3</li>
61         </ol>
62         <ul id="ul">
63             <li>A</li>
64             <li>B</li>
65             <li>C</li>
66         </ul>
67         <script type="text/javascript">
68             var li = document.querySelectorAll("ol li");
69             var lis = document.querySelectorAll("ul li");
70             
71             lis[0].className="show";
72             li[0].className = "bg";
73             for(var i=0;i<li.length;i++){
74                 li[i].index = i;
75                 li[i].onmouseover = function(){
76                     clear();
77                     this.className = "bg";
78                     lis[this.index].className = "show";
79                 }
80             }
81             
82             function clear(){
83                 for(var j=0;j<lis.length;j++){
84                     lis[j].className="";
85                     li[j].className="";
86                 }
87             }
88         </script>
89     </body>
90 </html>

 

js常用特效——选项卡效果

标签:.class   size   block   poi   text   one   abs   asc   char   

原文地址:http://www.cnblogs.com/web-wjg/p/7136773.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!