原生JS畫的tab選項卡

來源:互聯網
上載者:User

標籤:margin   ntop   this   選項卡   set   har   http   list   ack   

 記錄一下原生js寫的tab選項卡

滑鼠滑入可以切換圖片

離開之後自動切換

 

<!DOCTYPE html><html lang="en">
<head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>圖片切換</title> <style> * { margin: 0; padding: 0; list-style: none; }
.wrap { height: 170px; width: 490px; overflow: hidden; position: relative; margin: 100px auto; }
.wrap ul { position: absolute; /* overflow: hidden; */ }
.wrap ul li { height: 170px; display:none; }
.wrap ol { position: absolute; right: 5px; bottom: 10px; }
.wrap ol li { height: 20px; width: 20px; background: #ccc; border: solid 1px #666; margin-left: 5px; color: #000; float: left; line-height: 20px; text-align: center; cursor: pointer; }
.wrap ol .on { background: #E97305; color: #fff; } </style></head>
<body> <div class="wrap" id=‘wrap‘> <ul id="pic"> <li style="display:block"><img src="http://img.mukewang.com/54111cd9000174cd04900170.jpg" ></li> <li><img src="http://img.mukewang.com/54111dac000118af04900170.jpg" ></li> <li><img src="http://img.mukewang.com/54111d9c0001998204900170.jpg" ></li> <li><img src="http://img.mukewang.com/54111d8a0001f41704900170.jpg" ></li> <li><img src="http://img.mukewang.com/54111d7d00018ba604900170.jpg" ></li> </ul> <ol id="list"> <li class="on">1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ol> </div><script>window.onload = function () {var warp = document.getElementById("wrap"),pic = document.getElementById("pic")list = document.getElementById("list").getElementsByTagName("li"),timer = null,index = 0;function autoplay() {index++;if (index >= list.length) {index = 0;}changeoption(index);}function changeoption( curIndex){for (var j = 0; j < list.length; j++) {list[j].className = ""}list[curIndex].className = "on";pic.style.marginTop = -170 * (curIndex) + "px";index = curIndex;
} function tab() { for (var i = 0; i < list.length; i++) { list[i].id = i; list[i].onmouseover = function () { clearInterval(timer); changeoption(this.id); } list[i].onmouseout = function () { clearInterval(timer); timer = setInterval(autoplay, 2000) } } clearInterval(timer); timer = setInterval(autoplay, 2000) } tab(); }</script></body>
</html>

原生JS畫的tab選項卡

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.