<!DOCTYPE?html>
<html>
<head>
<title></title>
<style?type="text/css">
*{
margin:0;
padding:0;
}
#sdiv{
width:?200px;
height:200px;
background-color:skyblue;
float:left;
}
#div{
width:?300px;
height:200;
position:relative;
left:?-200px;
}
#span{
float:left;
font-size:?20px;
background:?#456;
margin-top:?80px;
line-height:?18px;
}
</style>
<script?type="text/javascript">
window.onload=function(){
var?span=document.getElementById("span");
var?div=document.getElementById("div");
var?sdiv=document.getElementById("sdiv");
span.onmouseover=function(){
move(0);
}
sdiv.onmouseout=function(){
move(-200)
}
}
function?move(target){
var?div=document.getElementById("div");
var?speed=0;
clearInterval(timer);
var?timer=setInterval(function(){
if?(div.offsetLeft==target)?{
clearInterval(timer)
}else?if(div.offsetLeft<target){
speed?=?10;
div.style.left=div.offsetLeft+speed+"px";
}else?if(div.offsetLeft>target){
speed?=?-10;
div.style.left=div.offsetLeft+speed+"px"
};
},30)
}
</script>
</head>
<body>
<div?id="div">
<div?id="sdiv"></div>
<span?id="span">分<br/>享</span>
</div>
</body>
</html>一個(gè)onmouseover和onmouseout觸發(fā)的動(dòng)畫(huà),但在同時(shí)觸發(fā)時(shí)(比如移開(kāi)sdiv時(shí)同時(shí)經(jīng)過(guò)span的動(dòng)畫(huà)還在執(zhí)行)會(huì)給target輸入兩個(gè)值,如何解決這個(gè)問(wèn)題?
關(guān)于js制作側(cè)拉動(dòng)畫(huà)的問(wèn)題
MR158
2016-02-03 18:12:54