javascript - Jquery div layers animate problem -
i started learning jquery , problem baffles me. have `div`s in container , when mouse on them resizes div , shifts divs in front offset. on mouseout, shifts div subtracting offset. current code: <html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> <script language="javascript1.2"> function resize(obj) { shift(parseint(obj.id[obj.id.length-1])); $("#"+obj.id).height("100px").width("100px") ; } function shift(id) { for(var i=id+1;i<=4;i++) { $("#hello"+i).stop().animate({"left":"+=60px"},1000) ; } } function shrink(obj) { $("#"+obj.id).height("64px").width("48px") ; reshrink(parseint(obj.id[obj.id.length-1])); } function reshrink(id) { document.getelementbyid('testvalue').innerhtml+=document.getelementbyid("hello2").style.left ; for(var i=id+1;i<=4;i++) { $("#hello"+i).stop().animate({"left":"-=60px"},1000) ; } document.getelementbyid('testvalue').innerhtml+=document.getelementbyid("hello2").style.left ; } </script> </head> <body> <h1>hello world!</h1> <div id="formwrapper" style="height:180;width:530;"> <div id="wrapper" style="position:relative;bottom:20px;width:460px;left:40px;height:160px;background-color:green;overflow:auto;" "> <div id="hello1" style="position:absolute;left:0px;height:64px;bottom:0px;width:48px; background-color:black;color:white;" onmouseover="resize(this);" onmouseout="shrink(this)"></div> <div id="hello2" style="position:absolute;left:49px;bottom:0px;height:64px;width:48px; background-color:maroon;color:white;" onmouseover="resize(this);" onmouseout="shrink(this)"></div> <div id="hello3" style="position:absolute;left:98px;bottom:0px;height:64px;width:48px; background-color:brown;color:white;" onmouseover="resize(this);" onmouseout="shrink(this)"></div> <div id="hello4" style="position:absolute;left:147px;bottom:0px;height:64px;width:48px; background-color:white;color:white;" onmouseover="resize(this);" onmouseout="shrink(this)"></div> </div> </div> <div id="testvalue" style="position:absolute;top:390px;background-color:yellow;height:100px;width:400px;"> </div> </body> </html> quite simple really, nothing complicated in it. found when mouseover , out rapid or maybe animation isn't complete - divs change more offset , overlaps. can please suggest how solve problem? **edit:** test, rapidly move mouse on first div. edit: after following tommy's advice...i'm still having problems it..the same error. don't know whether make new thread, here modified code: <code> <html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> <script language="javascript1.2"> var shouldmove = true,currprev=1,canshrink=false,attachedid=0 ; function resize(obj) { attachedid=parseint(obj.id[obj.id.length - 1]); if(currprev!=attachedid) { $("#hello"+currprev).height("64px").width("48px"); reshrink(); if(attachedid!=4) shift(4); else resizeimg(); currprev = attachedid; } } function resizeimg() { $("#hello"+attachedid).height("100px").width("100px"); } function shift(id) { if(id!=attachedid+1) $("#hello" + id).animate({"left": "+=52px", queue: true},function(){shift(--id)}); else $("#hello" + id).animate({"left": "+=52px", queue: true},function (){resizeimg()}); } function reshrink() { document.getelementbyid("testvalue").innerhtml+=document.getelementbyid("hello2").style.left; for(var i=currprev+1;i<=4;i++) $("#hello" + i).animate({"left": "-=52px", queue: true},1000); document.getelementbyid("testvalue").innerhtml+=document.getelementbyid("hello2").style.left; } </script> </head> <body> <h1>hello world!</h1> <div id="formwrapper" style="height:180;width:530;"> <div id="wrapper" style="position:relative;bottom:20px;width:460px;left:40px;height:160px;background-color:green;overflow:auto;" "> <div id="hello1" style="position:absolute;left:0px;height:100px;bottom:0px;width:100px; background-color:black;color:white;" onmouseover="resize(this);" ></div> <div id="hello2" style="position:absolute;left:102px;bottom:0px;height:64px;width:48px; background-color:maroon;color:white;" onmouseover="resize(this);" ></div> <div id="hello3" style="position:absolute;left:152px;bottom:0px;height:64px;width:48px; background-color:brown;color:white;" onmouseover="resize(this);" ></div> <div id="hello4" style="position:absolute;left:202px;bottom:0px;height:64px;width:48px; background-color:white;color:white;" onmouseover="resize(this);" ></div> </div> </div> <div id="testvalue" style="position:absolute;top:390px;background-color:yellow;height:100px;width:400px;"> </div> </body> </html> </code>
for quick fix try using .stop(true,true)
Comments
Post a Comment