Olivera Kovacevic
Olivera Kovacevic

Reputation: 717

animate on click works only once

I want the ul to move to the left by 200 each time, but it only happens once. Why?

$('a.next').click(function(e) {
        // e.preventDefault();
        $('ul#pikame').animate({
            'left': -200
        });
        e.preventDefault();
});

Upvotes: 4

Views: 2860

Answers (3)

webLacky3rdClass
webLacky3rdClass

Reputation: 649

You need to change the 'left': -200 to 'left': '-=200'

Upvotes: 5

MaGnetas
MaGnetas

Reputation: 5008

You should try:

'left': '-=200'

You're only setting the value statically.

Basically you're saying "set left value to -200". What you want to say is: "decrease left value by 200"

Upvotes: 8

AbstractChaos
AbstractChaos

Reputation: 4211

It's because -200 implies move to -200px not -200 more pixels try this.

$('a.next').click(function(e) {
        // e.preventDefault();
        $('ul#pikame').animate({
            'left': $('ul#pikame').position().left-200
        });
        e.preventDefault();
});

Upvotes: 1

Related Questions