方向?yàn)槭裁床幌褡?/h1>
<script>
?window.onload=function(){
? var oDiv=document.getElementById('div1');
? oDiv.onmouseover=function(){
? startMove();
? }
?}
?var timer=null;
?function startMove(){
? clearInterval(timer);
? ?var oDiv=document.getElementById('div1');
? ?timer=setInterval(function(){
? ?if(oDiv.offsetLeft<-200)
? ?{clearInterval(timer);}
? ?else{
? ?oDiv.style.left=oDiv.offsetLeft-1+'px';
? ?}
? ?},30)
? ?
?}
div1為什么向右跑
<script>
?window.onload=function(){
? var oDiv=document.getElementById('div1');
? oDiv.onmouseover=function(){
? startMove();
? }
?}
?var timer=null;
?function startMove(){
? clearInterval(timer);
? ?var oDiv=document.getElementById('div1');
? ?timer=setInterval(function(){
? ?if(oDiv.offsetLeft<-200)
? ?{clearInterval(timer);}
? ?else{
? ?oDiv.style.left=oDiv.offsetLeft-1+'px';
? ?}
? ?},30)
? ?
?}
div1為什么向右跑
2016-01-19
從你以上的代碼來(lái)看,
timer=setInterval(function(){
? ?if(oDiv.offsetLeft<-200)????????????????????????????????????//如果oDiv的left<200
? ?{clearInterval(timer);}????????????????????????????????????????//清除定時(shí)器timer
? ?else{
? ?oDiv.style.left=oDiv.offsetLeft-1+'px';????????????//else,oDiv的left每隔30ms減一個(gè)像素(也就是像左移動(dòng)1px)
? ?}
? ?},30)
ps:請(qǐng)你仔細(xì)查看下代碼,應(yīng)該會(huì)理解的,如果不理解歡迎貼出整個(gè)代碼,幫你分析下。
望采納~