Dimitri Vorontzov
Dimitri Vorontzov

Reputation: 8104

jQuery: how to express the width of a div + a few more pixels?

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

Answers (3)

shaunsantacruz
shaunsantacruz

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

Sarfraz
Sarfraz

Reputation: 382696

Why not try this instead:

$('#mydiv').animate({left:-($('#mydiv').width() + 100)},1000);

Upvotes: 1

crush
crush

Reputation: 17013

$('#mydiv').animate({left:-($('#mydiv').outerWidth() + 100)},1000);

Upvotes: 1

Related Questions