Gaddafi Rusli
Gaddafi Rusli

Reputation: 320

Get calculated percentage value in CSS using jQuery in Webkit browsers

I'm creating a simple sliding motion. But the div that is sliding in is using percentage for its width and right positioning.

The problem is in Webkit browsers. The value that I get using jQuery is actually the Percentage itself, while in Firefox, jQuery returned the calculated value of the percentage, based on the width of the parent element.

See here: http://jsfiddle.net/flisterz/ChZLu/

Click the trigger, and u can see the "right" value is the % value on your first click on Webkit (first click only). In Firefox, the "right" value is already the correctly calculated on even on first click.

Any tips? Thanks!

Upvotes: 1

Views: 744

Answers (1)

Justin808
Justin808

Reputation: 21512

It might be that you have to get the position(). Seeing as things are generally positioned top/left I've made the example use left rather than right. It still is setup in css using percents.

A little more math and you can use right if you really need to.

See: http://jsfiddle.net/ChZLu/1/

Upvotes: 1

Related Questions