<meta charset="utf-8">
<style>
# box {width: 300 px; height: 400px; margin: 0 auto; border: 1px solid #000; Background: # FBE9EF; }
Ul {padding: 0; margin: 0; float: left; }
Li {list - style: none; Width: 125 px; height: 90px; Margin: 0 px 10 px 5 px 10 px; border: 1px solid #000; position: relative; Overflow: hidden; }
Img {width: 125 px; height: 90px; vertical-align: top; position: absolute; }
The img1 {top: 0; left: 0; }
. Img2 {top: 90 px; left: 0; }
</style>
<script>
Window. The onl oad=function () {
Var aImg=document. GetElementsByTagName (" img ");
Var aImg1=document. GetElementsByClassName (' img1 ');
Var aImg2=document. GetElementsByClassName (" img2 ");
Var aLi=document. GetElementsByTagName (" li ");
var arr=[];
Var arrImg=[' Img/1. GIF ', 'Img/2. GIF', 'Img/3. GIF', 'Img/4. GIF', 'Img/5. GIF', 'Img/6. GIF', 'Img/7. GIF', 'Img/8. GIF', 'Img/9. GIF', 'Img/10. GIF', 'Img/11. GIF', 'Img/12. GIF', 'Img/13. GIF', 'Img/14. GIF', 'Img/15. GIF', 'Img/16. GIF'].
var timer=null;
for(var i=0; I
AImg [I] index=true;
};
The timer=setInterval (function () {
The Random ();//random number 1-8 random repeats
for(var i=0; I
If (aImg1 [j]. Journal of index) {
DoMove (aImg1 [j], 'top', 10, 90, the function () {
AImg1 [j]. Journal of index=false;
});
DoMove (aImg2 [j], 'top', 10, 0).
} else {
DoMove (aImg1 [j], 'top', 10, 0, the function () {
AImg1 [j]. Journal of index=true;
});
DoMove (aImg2 [j], 'top', 10, living);
}
}
}, 2000);
Function the Random () {//Random number 1-8 Random repeats
Var Num=math.h ceil (Math. The random () * aLi in length).
While (arr. Length
If (arr. Length==0) {
Arr. Push (isRandom);
} else {
If (arr. Join (', '). IndexOf (isRandom)==1) {
Arr. Push (isRandom);
}
}
}
};
The function doMove (obj, attr, dir, target, endFn) {
Dir=parseInt (getStyle (obj, attr)) & lt; The target? Dir: - dir;//dir=return value
clearInterval(obj.timer);
Obj. Timer=setInterval (function () {
Var speed=parseInt (getStyle (obj, attr)) + dir.
If (speed
Speed=target;
}
Obj. Style [attr]=speed + 'px';
If (speed==target) {
clearInterval(obj.timer);
//if (endFn) {endFn (); };
EndFn & amp; & EndFn ();//there is executed
}
40)},
};
The function getStyle (obj, attr) {
return obj.currentStyle? Obj. CurrentStyle [attr] : getComputedStyle (obj) [attr];
};
}
</script>
<body>