課程
/前端開發(fā)
/JavaScript
/焦點圖輪播特效
切換頁面一段時間后,再切回來輪播圖使勁滾!求大神幫忙解決,快快。拜托
2016-10-27
源自:焦點圖輪播特效 6-1
正在回答
<!doctype?html> <html?lang="en"> <head> ????<meta?charset="UTF-8"> ????<title>Document</title> ????<style> ?*?{ ????????????margin:?0; ?padding:?0; ?} ????????ul?li?{ ????????????list-style:?none; ?float:?left; ?/*display:?none;*/ ?} ????????ul?li?a?{ ????????????draggable:?false; ?} ????????img?{ ????????????vertical-align:?top; ?draggable:?false; ?-webkit-tap-highlight-color:transparent; ?} ????????#box?{ ????????????position:?relative; ?width:?520px; ?height:?280px; ?border:?1px?solid?#666; ?/*padding:?5px;*/ ?margin:?200px?auto; ?overflow:?hidden; ?} ????????#slider?{ ????????????width:?520px; ?height:?280px; ?position:?relative; ?} ????????ul?{ ????????????width:?1000%; ?position:?absolute; ?left:?0; ?top:?0; ?} ????????ol?{ ????????????/*width:?200px;*/ ????????????/*height:?20px;*/ ?position:?absolute; ?left:?50%; ?bottom:?20px; ?transform:?translateX(-50%); ?} ????????ol?li?{ ????????????float:?left; ?list-style:?none; ?width:?20px; ?height:?20px; ?border-radius:?50%; ?background-color:?silver; ?color:?#fff; ?text-align:?center; ?margin:?5px; ?cursor:?pointer; ?-webkit-touch-callout:?none;?/*?iOS?Safari?*/ ?-webkit-user-select:?none;?/*?Chrome/Safari/Opera?*/ ?-khtml-user-select:?none;?/*?Konqueror?*/ ?-moz-user-select:?none;?/*?Firefox?*/ ?-ms-user-select:?none;?/*?Internet?Explorer/Edge?*/ ?user-select:?none;?/*?Non-prefixed?version,?currently ?????????not?supported?by?any?browser?*/ ?} ????????.current?{ ????????????background-color:?orange; ?} ????</style> </head> <body> ????<div?id="box"> ????????<div?id="slider"> ????????????<ul> ????????????????<li><a?href=""?ondragstart='return?false;'><img?src="images/01.jpg"?alt=""/></a></li> ????????????????<li><a?href=""><img?src="images/02.jpg"?alt=""/></a></li> ????????????????<li><a?href=""><img?src="images/03.jpg"?alt=""/></a></li> ????????????????<li><a?href=""><img?src="images/04.jpg"?alt=""/></a></li> ????????????????<li><a?href=""><img?src="images/05.jpg"?alt=""/></a></li> ????????????</ul> ????????</div> ????</div> </body> <script> //????document.ondragstart=function(e){ //????????e.preventDefault(); //????????return?false; //????} // //????document.onselectionchange?=function(e){ //????????e.preventDefault(); //????????return?false; //????} ?let?box?=?document.getElementById("box"); ?let?slider?=?document.getElementById("slider"); ?let?ul?=?slider.children[0]; ?ul.appendChild(ul.children[0].cloneNode(true)); ?let?ulLis?=?ul.children; ?let?ol?=?document.createElement("ol"); ?box.appendChild(ol); ?for?(?let?i?=?0;?i?<?ulLis.length?-?1;?i++)?{ ?let?li?=?document.createElement("li"); ?ol.appendChild(li); ?li.innerText?=?i?+?1; ????} ?let?olLis?=?ol.children; ?olLis[0].className?=?"current"; ?function?animate(obj,?target)?{ ?if(obj.timer){ ?clearInterval(obj.timer); ????????} ?let?speed?=?target?>?obj.offsetLeft???10?:?-10; ?obj.timer?=?setInterval(function()?{ ?obj.style.left?=?obj.offsetLeft?+?speed?+?"px"; ?let?result?=?target?-?obj.offsetLeft; ?if(Math.abs(result)?<=?10)?{ ?clearInterval(obj.timer); ?obj.style.left?=?target?+?"px"; ????????????} ????????},?10) ????} ?for?(let?i?=?0;?i?<?olLis.length;?i++)?{ ?olLis[i].index?=?i; ?olLis[i].onclick?=?function?()?{ ?for?(let?i?=?0;?i?<?olLis.length;?i++)?{ ?olLis[i].className?=?""; ????????????} ?this.className?=?"current"; ?animate(ul,?-this.index?*?520); //????????????ul.style.left=-this.index?*?520+'px'; ?squre?=?key?=?this.index; ????????} ????} ?let?timer?=?null; ?let?key?=?0; ?let?squre?=?0; ?timer?=?setInterval(autoplay,1000); ?document.addEventListener('visibilitychange',function(){?//瀏覽器切換事件 ?if(document.visibilityState=='hidden')?{?//狀態(tài)判斷 //????????????????timer?=?null; ?clearInterval(timer); ????}else?{ ?timer?=?setInterval(autoplay,1000); //????????key++; ////????????alert(key,squre); //????????????timer; //????????if?(key?>?ulLis.length?-?1)?{ //????????????ul.style.left?=?0; //????????????key?=?1; //????????} //????????animate(ul,?-key?*?520); //????????squre++; //????????if?(squre?>?olLis.length?-1)?{ //????????????squre?=?0; //????????} //????????for?(let?i?=?0;?i?<?olLis.length;?i++)?{ //????????????olLis[i].className?=?""; //????????} //????????olLis[squre].className?=?"current"; ?} }); document.addEventListener('visibilitychange',function()?{?//瀏覽器切換事件 ?if?(document.visibilityState?==?'visible')?{?//狀態(tài)判斷 //????????????????timer?=?null; ?timer; ????} }) ?function?autoplay?()?{ //????????console.log(1); //????????let?jilu?=?location.href; //????????if?(location.href?!==?jilu)?{ //????????????return; //????????} ?key++; ?if?(key?>?ulLis.length?-?1)?{ ?ul.style.left?=?0; ?key?=?1; ????????} ?animate(ul,?-key?*?520); ?squre++; ?if?(squre?>?olLis.length?-1)?{ ?squre?=?0; ????????} ?for?(let?i?=?0;?i?<?olLis.length;?i++)?{ ?olLis[i].className?=?""; ????????} ?olLis[squre].className?=?"current"; ????} ?box.onmouseover?=?function()?{ ?clearInterval(timer); ????} ?box.onmouseout?=?function?()?{ ?timer?=?setInterval(autoplay,?1000); ????} slider.ondragstart?=?function?()?{ ?return?false; } //????window.onload?=?function?()?{ ////????????clearInterval(obj.timer); //????????ul.style.display?=?"show"; //????} </script> </html>
css和js都在一個頁面上寫著,html結(jié)構(gòu)中的圖片路徑自己改一下應(yīng)該就能看到效果了
把定時器清除,只留下一個定時器。
var play;
? ? ? if(play){
? ? ? ?clearInterval(play);
? ? ? ?play=null;
? ? ? }
我也是這個問題的樣子??!你解決沒??!
rainy_li3676598
代碼呢?
舉報
通過本教程學(xué)習(xí)您將能掌握非常實用的焦點圖輪播特效的制作過程
1 回答請問當(dāng)我把這個輪播圖頁面打開在瀏覽器,然后去瀏覽其他網(wǎng)頁,在回到輪播頁面,那個輪播圖會有很長一段時間在快速切換頁面
1 回答輪播圖片切換不完整
3 回答發(fā)現(xiàn)一個輪播圖切換有BUG
1 回答當(dāng)頁面不關(guān)閉,切出去間隔一會在切回來,圖片會快速的滾動
1 回答為什么我切換時,圖片之間會出現(xiàn)間隙
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2018-07-17
2017-06-25
把定時器清除,只留下一個定時器。
var play;
? ? ? if(play){
? ? ? ?clearInterval(play);
? ? ? ?play=null;
? ? ? }
2016-11-16
我也是這個問題的樣子??!你解決沒??!
2016-11-03
代碼呢?