主要思想:now代表当前图片,front代表优先级,当点击按钮now加一或者减一,front持续加一,使其要显示的图片在其他图片之上,在传入到move函数中实现滑动效果。
主要代码:
abtn[0].onclick=function(){
now--;
if(now<0){
now = 2;
}
++front;
aimg[now].style.zIndex =front;
aimg[now].firstElementChild.style.width = 0;
move(aimg[now].firstElementChild,'width',1000,200);
}
abtn[1].onclick = function(){
now++;
if(now>2){
now = 0;
}
++front;
aimg[now].style.zIndex =front;
aimg[now].firstElementChild.style.width = 0;
move(aimg[now].firstElementChild,'width',1000,200);
}}
function getStyle(obj,name){
if(obj.currentStyle){
return obj.currentStyle[name];
}else{
return getComputedStyle(obj,false)[name];
}
}//得到样式
function move(obj,attr,iTarget,speed){
obj.timer = null;//添加计时器属性
clearInterval(obj.timer);
obj.timer = setInterval(function(){
var cur = parseInt(getStyle(obj,attr));
if(cur==iTarget){
clearInterval(obj.timer);//alert("进入停止");
}else{
//var cur = parseInt(getStyle(obj,attr));
obj.style[attr] = cur+speed+'px';
}
},30);
















