jquery - Hover Animation Not Completed -


here fiddle illustration purposes: http://jsfiddle.net/wvrtl/

html:

    <section class="full-w blue">         <div class="container">             <div class="three"></div>             <div class="two"></div>         </div>     </section>       <section class="full-w red">         <div class="container">             <div class="two"></div>             <div class="three"></div>         </div>     </section> 

jquery

$('.full-w').hover(function() {    margintophero = $(this).find('.two').css("margin-top").replace("px", "");    newmargin = margintophero - 50 + "px";    oldmargin = margintophero + "px";     $(this).find('.two').stop().animate({ 'margin-top': newmargin }, 'fast');    }, function() {    $(this).find('.two').stop().animate({ 'margin-top': oldmargin }, 'fast'); }); 

enter image description here

the expected behavior when hovering on line, yellow rectangle moves up, , moves down original position when mouse leaves line. if move pointer 1 red line another, see yellow box lifts gradually until hits top of line.

enter image description here

i have retrieve margin-top value of element able revert position on mouseleave (the margin-top vary 1 .two another)

i understand tricky, unless totally missing something.

thanks!

the problem saving old value in shared global variable, use .data() api instead save previous valud

$('.full-w').hover(function() {      var margintophero = $(this).find('.two').css("margin-top").replace("px", "");     var newmargin = margintophero - 150 + "px";     $(this).data('oldmargin', margintophero + "px")      $(this).find('.two').stop().animate({ 'margin-top': newmargin }, 'fast'); }, function() {     $(this).find('.two').stop().animate({ 'margin-top': $(this).data('oldmargin') }, 'fast'); }); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -