rouken
2016-06-01 10:11
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>缓冲动画</title>
<style type="text/css">
div body{
margingin:0;
padding:0;
}
#div1{
width:250px;
height:200px;
background:red;
position:relative;top:0px;left:-200px;
}
</style>
<script>
window.onload=function{
oDiv = document.getElementById("div1");
oDiv.onmouseover = function(){
startMove(0);
}
oDiv.onmouseout = function(){
startMoove(-200);
}
}
var timer = null;
function startMove(iTarget){
clearInterval(timer);
var oDiv = document.getElementById("div1");
timer = setInterval(function(
var speed = 0;
if(odiv.offsetLeft > iTarget){
speed = -10;
}else{
speed = 10;
}
if(oDiv.offsetLeft == iTarget){
clearInterval(timer);
}else{
oDiv.style.left = oDiv.offsetLeft+speed+"px";
}
),30);
}
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>
都不知道怎么回答好,你代码写错了,window.onload=function(){}
timer = setInterval(function(){});
JS动画效果
113925 学习 · 1443 问题
相似问题
回答 1
回答 2
回答 2
回答 1
回答 1