Reputation: 8104
I want to animate a div to the left, to the width of the div + 100px.
I have this code:
$('#mydiv').animate({left:-$('#mydiv').outerWidth()},1000);
This animates it in 1000 milliseconds to the left, to the distance of the width of #mydiv.
How can I add 100 more pixels to that?
Would be grateful for your expertly advice!
Upvotes: 0
Views: 104
Reputation: 8930
Try:
var width = $('#mydiv').outerWidth();
$('#mydiv').animate({
left: (width + 100)
},1000);
Not sure why you need the subtraction operator before the left value?
Upvotes: 1
Reputation: 382696
Why not try this instead:
$('#mydiv').animate({left:-($('#mydiv').width() + 100)},1000);
Upvotes: 1
Reputation: 17013
$('#mydiv').animate({left:-($('#mydiv').outerWidth() + 100)},1000);
Upvotes: 1