qq_夕阳_11
2016-05-29 00:31
<!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>
在浏览器里用F12调试之后发现你在 startMove()这个函数处少写了“ } ”。38行后面。
JS动画效果
113917 学习 · 1502 问题
相似问题