基於JavaScript實現仿京東圖片輪播效果_javascript技巧
js實現仿京東圖片輪播效果,當滑鼠劃在視窗上面停止計時器,滑鼠離開窗口,開啟計時器,滑鼠劃在頁籤上面,停止計時器,手動切換,透過定義計時器封裝函數run,封裝函式changeOption,實現此效果,程式碼簡單易懂,需要的小夥伴直接複製拷貝轉走吧。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> *{margin:0;padding:0;list-style:none;} a{text-decoration: none;color: #fff;} #flash{width: 730px;height: 454px;margin: 100px auto;position: relative;cursor: pointer;} #pic li{position: absolute;top: 0;left: 0;z-index: 1;display: none;} #num{position: absolute;left: 40%;bottom: 10px;z-index: 2;cursor:default;} #num li{float: left;width: 20px;height: 20px;border-radius: 50%;background: #666;margin: 3px;line-height: 20px;text-align: center;color: #fff;cursor: pointer;} #num li.active{background: #f00;} .arrow{height: 60px;width: 30px;line-height: 60px;text-align: center;display: block;position: absolute;top:45%;z-index: 3;display: none;} .arrow:hover{background: rgba(0,0,0,0.7);} #flash:hover .arrow{display: block;} #left{left: 2%;} #right{right: 2%;} </style> <script type="text/javascript"> function $(id) { return typeof id==='string'?document.getElementById(id):id; } window.onload=function(){ var index=0; var timer=null; var pic=$("pic").getElementsByTagName("li"); var num=$("num").getElementsByTagName("li"); var flash=$("flash"); var left=$("left"); var right=$("right"); //单击左箭头 left.onclick=function(){ index--; if (index<0) {index=num.length-1}; changeOption(index); } //单击右箭头 right.onclick=function(){ index++; if (index>=num.length) {index=0}; changeOption(index); } //鼠标划在窗口上面,停止计时器 flash.onmouseover=function(){ clearInterval(timer); } //鼠标离开窗口,开启计时器 flash.onmouseout=function(){ timer=setInterval(run,2000) } //鼠标划在页签上面,停止计时器,手动切换 for(var i=0;i<num.length;i++){ num[i].id=i; num[i].onmouseover=function(){ clearInterval(timer); changeOption(this.id); } } //定义计时器 timer=setInterval(run,2000) //封装函数run function run(){ index++; if (index>=num.length) {index=0}; changeOption(index); } //封装函数changeOption function changeOption(curindex){ console.log(index) for(var j=0;j<num.length;j++){ pic[j].style.display="none"; num[j].className=""; } pic[curindex].style.display="block"; num[curindex].className="active"; index=curindex; } } </script> </head> <body> <div id="flash"> <ul id="pic"> <li style="display:block"><img src="http://img13.360buyimg.com/da/jfs/t2242/262/578407619/87636/4ffe0c5/56187ed2Nfed9a5b3.jpg" alt=""></li> <li><img src="http://img13.360buyimg.com/da/jfs/t2143/111/577347825/96150/e27180bd/561889b3N42ee62b5.jpg" alt=""></li> <li><img src="http://img20.360buyimg.com/da/jfs/t1825/234/1750370913/97529/b9229832/560b5ad3N054605f7.jpg" alt=""></li> <li><img src="http://img10.360buyimg.com/da/jfs/t2026/215/573306345/95654/a0211937/5618a735N1b3d8423.jpg" alt=""></li> <li><img src="http://img20.360buyimg.com/da/jfs/t2065/362/579832759/78899/6f349917/5618c680N3752bacc.jpg" alt=""></li> <li><img src="http://img10.360buyimg.com/da/jfs/t2023/45/384256123/101565/9b6e5daf/5604bdceN8c7d2ccf.jpg" alt=""></li> </ul> <ol id="num"> <li class="active">1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> </ol> <a href="javascript:;" class="arrow" id="left"><</a> <a href="javascript:;" class="arrow" id="right">></a> </div> </body> </html>
以上程式碼是不是很簡單啊,基於javascrit實現仿金東圖片輪播效果就製作成功了,由於時間原因沒有給大家展示效果圖,還請大家見諒。

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

熱門話題











Python和JavaScript開發者的薪資沒有絕對的高低,具體取決於技能和行業需求。 1.Python在數據科學和機器學習領域可能薪資更高。 2.JavaScript在前端和全棧開發中需求大,薪資也可觀。 3.影響因素包括經驗、地理位置、公司規模和特定技能。

JavaScript是現代Web開發的基石,它的主要功能包括事件驅動編程、動態內容生成和異步編程。 1)事件驅動編程允許網頁根據用戶操作動態變化。 2)動態內容生成使得頁面內容可以根據條件調整。 3)異步編程確保用戶界面不被阻塞。 JavaScript廣泛應用於網頁交互、單頁面應用和服務器端開發,極大地提升了用戶體驗和跨平台開發的靈活性。

如何在JavaScript中將具有相同ID的數組元素合併到一個對像中?在處理數據時,我們常常會遇到需要將具有相同ID�...

實現視差滾動和元素動畫效果的探討本文將探討如何實現類似資生堂官網(https://www.shiseido.co.jp/sb/wonderland/)中�...

學習JavaScript不難,但有挑戰。 1)理解基礎概念如變量、數據類型、函數等。 2)掌握異步編程,通過事件循環實現。 3)使用DOM操作和Promise處理異步請求。 4)避免常見錯誤,使用調試技巧。 5)優化性能,遵循最佳實踐。

深入探討console.log輸出差異的根源本文將分析一段代碼中console.log函數輸出結果的差異,並解釋其背後的原因。 �...

探索前端中類似VSCode的面板拖拽調整功能的實現在前端開發中,如何實現類似於VSCode...
