为了账号安全,请及时绑定邮箱和手机立即绑定

加上remove后失效,注释掉remove又可以了,为什么,大神们帮帮忙

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Document</title>

<link rel="stylesheet" type="text/css" href="css/style.css">

</head>

<body>

<div id="div">


</div>

<script type="text/javascript">

window.onload=function(){

var oDiv=document.getElementById("div");

oDiv.onmouseover=function(){


startMove();

}

oDiv.onmouseout=function(){


reMove();

}


}

var timer=null;

function startMove(){

clearInterval(timer);

           var oDiv=document.getElementById("div");

           

           timer=setInterval(function(){

            if (oDiv.offsetLeft==500) {

            clearInterval(timer);

            } 

            else {

            oDiv.style.left=oDiv.offsetLeft+1+"px";

            }

 

            },10)

        function reMove(){

clearInterval(timer);

           var oDiv=document.getElementById("div");

           

           timer=setInterval(function(){

            if (oDiv.offsetLeft==0) {

            clearInterval(timer);

            } 

            else {

            oDiv.style.left=oDiv.offsetLeft-1+"px";

            }

 

            },10)

            

}

</script>

</body>

</html>


正在回答

1 回答

在浏览器里用F12调试之后发现你在 startMove()这个函数处少写了“ } ”。38行后面。

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

加上remove后失效,注释掉remove又可以了,为什么,大神们帮帮忙

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号