<!DOCTYPE HTML>
<html>
<head>
<title>js动画缓动效果实现setInterval(),就是慢慢的停下来</title>
<meta charset="utf-8" />
<style>
* {
margin: 0;
padding: 0;
}
#box {
width: 100px;
height: 100px;
background-color: pink;
}
</style>
</head>
<body>
<div id="box"> </div>
<script>
var box = document.getElementById('box');
function move() {
box.style.marginLeft = box.offsetLeft + (300 - box.offsetLeft) / 10 + 'px';
if(box.offsetLeft == 300) {
clearTimeout(timer);
}
}
var timer = setInterval(move, 100);
</script>
</body>
</html>