javascript左右点击焦点图 js左右移动焦点图

javascript左右点击焦点图 js左右移动焦点图

javascript左右点击焦点图 js左右移动焦点图

javascript部分:

window.onload=function(){
var oBox=document.getElementById("box");
var oBtnL=document.getElementById("btnLeft");
var oBtnR=document.getElementById("btnRight");
var oLi=oBox.getElementsByTagName("li");
var oUl=oBox.getElementsByTagName("ul")[0];
var num=0;
var timer=null;
oBtnL.onclick=play
timer=setInterval(play,2000)
oBtnR.onclick=function(){
num++;
if(num==oLi.length){
num=0
}
oUl.style.left=-num*oLi[0].offsetWidth+"px";
}
function play(){
num--;
if(num==-1){
num=oLi.length-1
}
oUl.style.left=-num*oLi[0].offsetWidth+"px";
}
oBox.onmousemove=function(){
clearInterval(timer)
}
oBox.onmouseout=function(){
timer=setInterval(play,2000)
}
}

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: