天天看點

html 旋轉木馬 輪播,JS實作旋轉木馬式圖檔輪播效果

本文執行個體為大家分享了js圖檔輪播的具體代碼,供大家參考,具體内容如下

主要html代碼:

Document

  • html 旋轉木馬 輪播,JS實作旋轉木馬式圖檔輪播效果
  • html 旋轉木馬 輪播,JS實作旋轉木馬式圖檔輪播效果
  • html 旋轉木馬 輪播,JS實作旋轉木馬式圖檔輪播效果
  • html 旋轉木馬 輪播,JS實作旋轉木馬式圖檔輪播效果
  • html 旋轉木馬 輪播,JS實作旋轉木馬式圖檔輪播效果

function $(id){ return document.getElementById(id);}

var js_wrap = $("js_wrap");

var wrap_slide = $("wrap_slide");

var wrap_slide_arrow = $("wrap_slide_arrow");

var lis = wrap_slide.children[0].children;

var json = [

{

//1

width: 400,

top: 20,

left: 50,

opacity: 20,

z: 2

},

{

//2

width: 600,

top: 70,

left: 0,

opacity: 80,

z: 3

},

{

//3

width: 800,

top: 100,

left: 200,

opacity: 100,

z: 4

},

{

//4

width: 600,

top: 70,

left: 600,

opacity: 80,

z: 3

},

{

//5

width: 400,

top: 20,

left: 750,

opacity: 20,

z: 2

}

]

change(); //将各個圖檔按照json鋪開層次

var jieliu = true;

//兩個按鈕點選事件

var as = wrap_slide_arrow.children;

for(var k in as){

as[k].onclick = function(){

if(this.className == "prev"){

//所有圖檔逆時針旋轉,相當于圖檔不動,json的第一個删除并插到最後一個

if(jieliu == true){

change(false);

jieliu = false;

}

}else if(this.className == "next"){

//所有圖檔順時針旋轉,相當于圖檔不動,json的最後一個删除并插到第一個

if(jieliu == true){

change(true);

jieliu = false;

}

}

}

}

function change(flag){

if(flag){

//所有圖檔順時針旋轉,相當于圖檔不動,json的最後一個删除并插到第一個

json.unshift(json.pop());

}else{

//所有圖檔逆時針旋轉,相當于圖檔不動,json的第一個删除并插到最後一個

json.push(json.shift());

}

for(var k in json){

animate(lis[k],{

width: json[k].width,

top: json[k].top,

left: json[k].left,

opacity: json[k].opacity,

zIndex: json[k].z

},function(){ jieliu = true;}); //當動畫執行完,執行回調函數,此時置節流為true

}

}

var timer = null;

timer = setInterval(autoPlay,2000);

function autoPlay(){

if(jieliu == true){

change(true);

jieliu = false;

}

}

js_wrap.onmouseover = function(){

clearInterval(timer);

animate(wrap_slide_arrow,{opacity:100});

}

js_wrap.onmouseout = function(){

clearInterval(timer);

timer = setInterval(autoPlay,2000);

animate(wrap_slide_arrow,{opacity:0});

}

主要css代碼:

blockquote,body,button,dd,dl,dt,fieldset,form,h1,h2,h3,h4,h5,h6,hr,input,legend,li,ol,p,pre,td,textarea,th,ul{margin:0;padding:0}

body,button,input,select,textarea{font:12px/1.5 "Microsoft YaHei", "微軟雅黑", SimSun, "宋體", sans-serif;color: #666;}

ol,ul{list-style:none}

a{text-decoration:none}

fieldset,img{border:0;vertical-align:top;}

a,input,button,select,textarea{outline:none;}

a,button{cursor:pointer;}

.w-wrap{

width: 1200px;

margin: 100px auto;

}

.wrap-slide{

position: relative;

}

.wrap-slide li{

position: absolute;

left: 200px;

top: 0;

}

.wrap-slide li img{

width: 100%;

}

.wrap-slide-arrow{

opacity: 0;

position: relative;

}

.prev,.next{

width: 76px;

height: 112px;

position: absolute;

top: 50%;

margin-top: -56px;

background: url(../images/prev.png) no-repeat;

}

.next{

right: 0;

background: url(../images/next.png) no-repeat;

}

以上就是本文的全部内容,希望對大家的學習有所幫助,也希望大家多多支援腳本之家。