所以应该改成onmouseout=function(){start()}
就ok了
大过年的,你还这么专心啊 ?
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<style>
*{margin: 0padding: 0}
img{position: relativeleft: 0top: 100px}
.div1{width: 100pxheight: 100pxbackground: greenposition: absoluteleft: 0top: 0z-index: 999}
</style>
</head>
<body style="height:2000px">
<div class="div1">left</div>
<script>
var x=0
var y=0
var i=1
var j=1
var xWidth=$(window).width()-100
var yHeight=$(window).height()-100
setInterval(function(){
if(x==xWidth){
i=-1
}
if(x<0){
i=1
}
x=i+x
if(y==yHeight){
j=-1
}
if(y<0){
j=1
}
y=j+y
$(".div1").css({"left":x,"top":y})
}, 5)
</script>
</body>
</html>