哪里不對啊,離開縮不回去了好奇怪
window.onload=function(){
?? ???? ??? ??? ?odiv=document.getElementById("div1");
?? ???? ??? ??? ?odiv.onmouseover=function(){
?? ???? ??? ??? ??? ?//move(10,0);
?? ???? ??? ??? ??? ?move(0);
?? ???? ??? ??? ?}
?? ???? ??? ??? ?odiv.onmouseout=function(){
?? ???? ??? ??? ??? ?//out();
?? ???? ??? ??? ??? ?//move(-10,-200);
?? ???? ??? ??? ??? ?move(-200);
?? ???? ??? ??? ?}
?? ???? ??? ?}
?? ???? ??? ?var timer=null;
?? ???? ??? ?function move(target){
?? ???? ??? ??? ?clearInterval(timer);
?? ???? ??? ??? ?odiv=document.getElementById("div1");
?? ???? ??? ??? ?timer = setInterval(function(){
?? ???? ??? ??? ??? ?var speed=0;
?? ???? ??? ??? ??? ?if(odiv.offsetLeft>target){
?? ???? ??? ??? ??? ??? ?speed = -10;
?? ???? ??? ??? ??? ?}else{
?? ???? ??? ??? ??? ??? ?speed=10;
?? ???? ??? ??? ??? ?}
?? ???? ??? ??? ??? ?if(odiv.offsetLeft>=target){
?? ???? ??? ??? ??? ??? ?clearInterval(timer);
?? ???? ??? ??? ??? ?}else{
?? ???? ??? ??? ??? ??? ?odiv.style.left =odiv.offsetLeft + speed+"px"; //變大
?? ???? ??? ??? ??? ?}
?? ???? ??? ??? ??? ?
?? ???? ??? ??? ?},500);
?? ???? ??? ?}
?? ???? ????
2017-11-01
當(dāng)div完全顯示的時(shí)候,odiv.offsetleft為0,想讓它縮回去,你設(shè)target為-200,然而你判斷條件是odiv.offsetLeft>=target,條件成立,執(zhí)行??clearInterval(timer);,自然縮不回去。