明星单品tab

  1 <!DOCTYPE html>
  2 <html>
  3 
  4     <head>
  5         <meta charset="UTF-8">
  6         <title></title>
  7         <style>
  8             * {
  9                 margin: 0px;
 10                 padding: 0px;
 11                 list-style: none;
 12             }
 13             
 14             h2 {
 15                 margin-bottom: 20px;
 16                 background: #ccc;
 17                 display: inline-block;
 18             }
 19             
 20             h2 span {
 21                 background: blue;
 22                 display: inline-block;
 23                 width: 40px;
 24                 height: 40px;
 25                 text-align: center;
 26                 cursor: pointer;
 27             }
 28             
 29             div {
 30                 width: 600px;
 31                 height: 200px;
 32                 border: 2px solid blue;
 33                 overflow: hidden;
 34                 position: relative;
 35             }
 36             
 37             ul {
 38                 width: 1200px;
 39                 position: absolute;
 40                 left: 0px;
 41                 transition: 0.2s linear;
 42             }
 43             
 44             ul li {
 45                 width: 200px;
 46                 height: 200px;
 47                 background: #eee;
 48                 float: left;
 49             }
 50             
 51             ul li:nth-child(even) {
 52                 background-color: green;
 53             }
 54             
 55             ul.now1 {
 56                 left: -600px;
 57             }
 58             
 59             ul.now2 {
 60                 left: 0px;
 61             }
 62             
 63             span.disable {
 64                 background: #ccc;
 65                 color: #eee;
 66                 cursor: default;
 67             }
 68         </style>
 69     </head>
 70 
 71     <body>
 72         <h2><span>&lt;</span> | <span>&gt;</span> </h2>
 73         <div>
 74 
 75             <ul>
 76                 <li>AAA</li>
 77                 <li>BB</li>
 78                 <li>CC</li>
 79                 <li>DD</li>
 80                 <li>EE</li>
 81                 <li>FF</li>
 82             </ul>
 83         </div>
 84 
 85         <script>
 86             var btn = document.querySelectorAll("span");
 87             var ul = document.querySelector("ul");
 88             var h2 = document.querySelector("h2");
 89             var i = 0,
 90                 timer;
 91             btn[1].onclick = function() {
 92 
 93                 ul.className = "now1";
 94                 this.className = "disable"
 95                 this.previousElementSibling.className = "";
 96                 i = 1;
 97             }
 98             btn[0].onclick = function() {
 99                 ul.className = "now2";
100                 this.className = "disable"
101                 this.nextElementSibling.className = "";
102                 i = 0;
103             }
104 
105             //自动走动
106 
107             function AutoPlay() {
108                 if(i == 0) {
109                     i = 1;
110                     ul.className = "now1";
111                     btn[0].className = ""
112                     btn[1].className = "disable"
113                 } else if(i == 1) {
114                     i = 0;
115                     ul.className = "now2";
116                     btn[0].className = "disable"
117                     btn[1].className = "";
118                 }
119 
120             }
121 
122             timer = setInterval(AutoPlay, 2000);
123 
124             h2.onmouseover = function() {
125                 clearInterval(timer)
126             }
127             h2.onmouseout = function() {
128                 timer = setInterval(AutoPlay, 2000);
129             }
130         </script>
131     </body>
132 
133 </html>

 

转载于:https://www.cnblogs.com/oklfx/p/7499724.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值