Adam91
Adam91

Reputation: 83

animate() jquery failed in my case

$(document).ready(function(){
    $('.more').click(function() {
        var thumbsBlock = $(this).siblings('.thubmnailsWrap');

        $($(this), thumbsBlock).animate({
            'left' : "-=60px" //moves left
        });
    });
});

I use siblings and expect .thubmnailsWrap to move along with .more but failed. check my demo here http://jsfiddle.net/pdjkh69m/4/

I solved it, here is the code http://jsfiddle.net/pdjkh69m/8/ but I wonder why in my previous code, the multiple selector jst does not work, any idea? I kinda want to continue with duplicated code.

Upvotes: 1

Views: 119

Answers (3)

budamivardi
budamivardi

Reputation: 760

$($(this), thumbsBlock)

this is wrong method

this works

http://jsfiddle.net/pdjkh69m/10/

Upvotes: 0

himanshu
himanshu

Reputation: 1797

 $(document).ready(function () {


    $('.more').click(function () {


        var thumbsBlock = $(this).siblings('.thubmnailsWrap');

        $(thumbsBlock).animate({
            'left': "-=60px"
        });

    });
});

this is the code are you looking for

Upvotes: 0

Anton
Anton

Reputation: 32581

Your css is incorrect, you need to use class selector . for the div to get position:absolute for animate to work.

Also use .add() to add another element to your jQuery object

thumbsBlock.add(this).animate({
    'left': "-=60px"
},1000);

DEMO

Upvotes: 1

Related Questions