您的位置:首页 > 其它

缓冲运动(变速)

2017-10-17 09:13 127 查看
点击打开链接

<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">
<title></title>
<!--速度=(目标值-当前值)/缩放系数-->
<style type="text/css">
*{
padding: 0;
margin: 0;
}
#box{
width: 200px;
height: 400px;
background: darkcyan;
position: absolute;
left: -200px;
}
</style>
<script type="text/javascript">
window.onload=function(){
var obtn=document.getElementById('btn');
var obox=document.getElementById('box');
var timer=null;

function move(){
clearInterval(timer);
timer=setInterval(function(){

//速度=(目标值-当前值)/缩放系数
var speed=(0-obox.offsetLeft)/20;    
obox.style.left=obox.offsetLeft+speed+'px';
},30);
}

obtn.onclick=function(){
move();
}
}

</script>
</head>
<body>
<input type="button" name="btn" id="btn" value="移出" />
<div id="box">
</div>
</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: