【www.bbyears.com--js教程】
代码如下脚本之家
<script type="text/javascript">
functionls(){
varp=true;//开关,true开,false关
varxx=document.getElementById('xx');
varxxleft = parseInt(xx.style.left);
varspeed = 20;
vart=setInterval(rollRight,speed);
//向左移动
functionrollLeft(){
if(p){
xxleft--;
xx.style.left = xxleft+'px';
if(xxleft <=0 ){
clearInterval(t);
t=setInterval(rollRight,speed);
}
}
}
//向右移动
functionrollRight(){
if(p){
xxleft++;
xx.style.left = xxleft+'px';
if(xxleft >= 300){
clearInterval(t);
t=setInterval(rollLeft,speed);
}
}
}
}
ls();
</script>
运行效果图如下: