Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple jquery .hover() method for each class element

haven't done much jquery and ran into a problem. I'd like to bind hover event for all div's with class .social-tile. I do it like this:

$(function(){
    var social_default = $('.social-tile').css('margin-right');
    $('.social-tile').each(function(){
        $(this).hover(function(){
            $(this).animate({
                'margin-right': '0px' 
            },500);
        },function(){
            $(this).animate({
                'margin-right': social_default 
            },500);
        });
    });
});

When I hover over one element, animations for all divs are triggered and they move all at one time. I'd like to animate only specific element which I hover.

Probably there is a really easy fix here, thank you.

like image 942
Mikk Avatar asked Apr 21 '26 16:04

Mikk


1 Answers

try this, sorry - working demo here: http://jsfiddle.net/8vFAD/1/

$('.social-tile').live('mouseover', function(){
    $(this).animate({ 'margin-left': '15px'} ,500).animate({ 'margin-left': '30px'} ,500);
});
like image 57
ezmilhouse Avatar answered Apr 26 '26 05:04

ezmilhouse



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!