JacobTheDev
JacobTheDev

Reputation: 18550

Animating marginLeft with jQuery

I can't figure out to animate marginLeft with jQuery. I need it to subtract 938px every time a user clicks on a link, which was working fine when I was using .css(), but I can't figure out how to make it work with .animate().

$("#full-wrapper #full").animate({
    marginLeft, -=938px
}, 500);

Can anyone figure out why this doesn't work? This was my CSS version:

$("#full-wrapper #full").css("marginLeft","-=938px");

I was using CSS3 for animation, but need to make it work in older browsers.

Upvotes: 23

Views: 67498

Answers (3)

ShankarSangoli
ShankarSangoli

Reputation: 69915

Replace comman(,) by colon(:).

$("#full-wrapper #full").animate({
    marginLeft: "-=938px"
}, 500);

Upvotes: 3

Rafay
Rafay

Reputation: 31043

$("#full-wrapper #full").animate({
    marginLeft: '-=938px'
}, 500);

Upvotes: 1

Rory McCrossan
Rory McCrossan

Reputation: 337714

There's a syntax error in your code, as you are passing parameters in an object to animate() you should use : not , to delimit each attribute. Try this:

$("#full-wrapper #full").animate({
    marginLeft: '-=938px'
}, 500);

Example fiddle

Upvotes: 49

Related Questions