鼠标移出没反应

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>无标题文档</title>

<script>

window.onload = function(){

var xiem = document.getElementById('xie');

xiem.onmousemove =function(){ 

    startMove();

        }

    xiem.onmouseout = function(){

startMOve1();

}

   }

var time = null;

function startMove(){

clearInterval(time);

time = setInterval(function(){

var xiem = document.getElementById('xie');

if(xiem.offsetLeft== 0){

    clearInterval(time);

    }

else{

xiem.style.left=xiem.offsetLeft+10+'px';

}

},30)

}


function startMove1(){

var time = null;

clearInterval(time);

time = setInterval(function(){

var xiem = document.getElementById('xie');

if(xiem.offsetLeft==-200){

    clearInterval(time);

    }

else{

xiem.style.left=xiem.offsetLeft-10+'px';

}

},30)

}

</script>

<style type="text/css">

*{margin:0; padding: 0;}

#xie{width:230px;

     height:100px;

background:#666; 

font-size:16px;

position:relative;

     left:-200px;

}


</style>

</head>


<body>

<div id="xie">

</div>

</body>

</html>


xiemioc
浏览 1561回答 2
2回答

qq_大寒_2

window.onload = function(){ var xiem = document.getElementById('xie'); xiem.onmousemove =function(){     startMove();         }     xiem.onmouseout = function(){ startMove1(); }    }startMOve1()=>startMove1(); 小写o

刚毅87

  你是不是想用鼠标移入事件 onmouseenter 或 onmouseoveronmousemove 是鼠标移动事件
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript