Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a reverse jquery animation when rolloff

I'm trying to make the title animate down when you rolloff the hit area. You will notice its currently working on rollover, title animates up 20px, so basically when you rolloff the title should return to its starting position.

Live Example

HTML

<div class="thumb">
    <div class="content">
        <div class="copy">
             <h1>Title</h1>
        </div>
    </div>
</div>

JS

$('.content').hide().removeClass('content').addClass('content-js');

$('.thumb').hover(function () {
    $(this).find('.content-js').fadeToggle();
    $('.copy h1').animate({'margin-top':'0px'});
});
like image 947
Rob Avatar asked Feb 26 '26 20:02

Rob


2 Answers

Just add another animation in the .hover() (which takes two parameters : mouse enter and mouse leave)

http://jsfiddle.net/aGcpR/12/

like image 137
Ven Avatar answered Mar 01 '26 09:03

Ven


Instead of the hover() shortcut, use mouseenter / mouseleave, and put everything in one single function :

$('.content').hide().removeClass('content').addClass('content-js');

$('.thumb').on('mouseenter mouseleave', function(e) {
    var dir = e.type == 'mouseenter';
    $(this).find('.content-js').fadeToggle();
    $('.copy h1').animate({'margin-top': (dir ? 0 : 20)});
});

FIDDLE

like image 45
adeneo Avatar answered Mar 01 '26 10:03

adeneo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!