JS原生帶小白點(diǎn)輪播圖實(shí)例講解
咱們剛剛說了js原生輪播圖,現(xiàn)在給他加上可以隨著一起走動(dòng)的小圓點(diǎn)吧!
css代碼:
*{ margin:0px; padding: 0px; } ul{ width: 2500px; height: 300px; position: absolute; } li{ float: left; list-style: none; } img{ width: 500px; height: 300px; } div{ width: 500px; height: 300px; margin: 50px auto; position: relative; overflow: hidden; } /*小白點(diǎn)的ul*/ #round_ul{ width:300px; height: 30px; /*background:yellow;*/ position: relative; margin: 250px auto; } #round_ul li{ width: 20px; height:20px; border-radius: 50%; background: #2196f3; margin-left: 50px; cursor: pointer; }
HTML代碼:
<div> <ul> <li><img src="img/31.jpg"></li> <li><img src="img/32.jpG"></li> <li><img src="img/33.jpG"></li> <li><img src="img/34.jpg"></li> <li><img src="img/31.jpg"></li> </ul> <ul id="round_ul"> <li></li> <li></li> <li></li> <li></li> </ul>
JS部分:
<script type="text/javascript"> //頁面加載完成后 執(zhí)行代碼 window.onload = function(){ //獲取 ul var imgUl = document.getElementsByTagName("ul")[0]; var groundUl = document.getElementById("round_ul"); //把第一個(gè)小白點(diǎn)修改成紅色children 節(jié)點(diǎn)的子節(jié)點(diǎn)(不算空白節(jié)點(diǎn)) groundUl.children[0].style.backgroundColor = "red"; var sId,x = 0; //開始計(jì)時(shí)器函數(shù) function fn(){ sId = setInterval(abc,10); } function abc(){ //每隔10秒修改ul的坐標(biāo),修改1px imgUl.style.left = x-- +"px"; //如果一張圖片完全進(jìn)入到div中 if(x % 500 == 0){ //調(diào)用修改小白點(diǎn)函數(shù) if(x == -2000){ x = 0; imgUl.style.left = 0 +"px"; } changLi(Math.abs(x/500));//調(diào)用修改小白點(diǎn)方法 clearInterval(sId);//暫定定時(shí)器 setTimeout(fn,1000);//隔100毫秒在次啟動(dòng)定時(shí)器 } } fn(); //修改小白點(diǎn)方法 function changLi(num){ //遍歷小白點(diǎn)數(shù)組 for(var x = 0;x<4;x++){ //把所有的點(diǎn)修改成藍(lán)色 groundUl.children[x].style.backgroundColor = "#2196f3"; } //把相對應(yīng)的小白點(diǎn)修改成紅色 groundUl.children[num].style.backgroundColor = "red"; } } </script>
就是這樣?。∧愣藛???
以上這篇JS原生帶小白點(diǎn)輪播圖實(shí)例講解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
js實(shí)現(xiàn)div模擬模態(tài)對話框展現(xiàn)URL內(nèi)容
這篇文章主要介紹了js實(shí)現(xiàn)div模擬模態(tài)對話框展現(xiàn)URL內(nèi)容的功能,涉及javascript動(dòng)態(tài)操作頁面元素樣式與ajax調(diào)用的相關(guān)技巧,需要的朋友可以參考下2016-05-05ES6使用新特性Proxy實(shí)現(xiàn)的數(shù)據(jù)綁定功能實(shí)例
這篇文章主要介紹了ES6使用新特性Proxy實(shí)現(xiàn)的數(shù)據(jù)綁定功能,結(jié)合具體實(shí)例形式分析了ES6使用Proxy實(shí)現(xiàn)數(shù)據(jù)綁定具體原理、操作步驟與相關(guān)注意事項(xiàng),需要的朋友可以參考下2020-05-05uniapp電商小程序?qū)崿F(xiàn)訂單30分鐘倒計(jì)時(shí)
這篇文章主要為大家詳細(xì)介紹了uniapp電商小程序?qū)崿F(xiàn)訂單30分鐘倒計(jì)時(shí),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-11-11JavaScript學(xué)習(xí)總結(jié)之JS、AJAX應(yīng)用
這篇文章主要介紹了JavaScript學(xué)習(xí)總結(jié)JS AJAX應(yīng)用 的相關(guān)資料,需要的朋友可以參考下2016-01-01JavaScript實(shí)現(xiàn)自動(dòng)生成帶水印的圖片
這篇文章主要來和大家一起討論如何利用JavaScript實(shí)現(xiàn)一個(gè)復(fù)雜功能,該功能可以自動(dòng)為圖片添加水印,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-01-01