caramba
caramba

Reputation: 22480

jquery using same animation on many elements, how to do best?

The animate functions does thre times exactly the same thing. So how can I do this while writing .animate(.. only once? There should be an easy way but I couldn't figure out.

This is what I've got: see fiddle

$('.button').on('click',function(){
    $('header').animate({
        'left': '315px'
    }, 500, function() {
    });
    $('main').animate({
        'left': '315px'
    }, 500, function() {
    });
    $('footer').animate({
        'left': '315px'
    }, 500, function() {
    });
});

Upvotes: 2

Views: 32

Answers (1)

Milind Anantwar
Milind Anantwar

Reputation: 82241

By using comma separated multiple selectors. This way:

$('header,main,footer').animate({
    'left': '315px'
}, 500, function() {
});

Working Fiddle

Upvotes: 3

Related Questions