龙缘
2019-11-06 11:34
<div id="item" class="main"><span id = "spare" class = "sp">分享</span></div>
<script type="text/javascript">
window.onload = function (){
var item=document.getElementById("item");
item.onmouseover = function(){
startMove(0);
}
item.onmouseout = function(){
startMove(-400);
}
}
var timer = null;
function startMove(target){
var item=document.getElementById("item");
clearInterval(timer);
timer = setInterval (function(){
speed = (item.offsetLeft > target)?-10 : 10;
if (item.offsetLeft == target){
clearInterval(timer);
}
else{
item.style.left = item.offsetLeft + speed + "px";
}
},30)
}
</script>
JS动画效果
113925 学习 · 1443 问题
相似问题