开发者

jQuery positioning differences between Chrome(webkit) and Firefox

While working on a jQuery UI range slider, I was mainly debugging in chrome. I needed to make the range have a limit so I would grab the left position of one of the handles like so:

$el.css('left');

Which would give me the left position as a percentage: 84%. However, when I tested in Firefox, it was returning the value in pixels.

Has anyone experienced this before? Based on lo开发者_运维技巧oking at the DOM in Firebug, Firefox does recognize percent-based left positioning but it doesn't seem to return that as a value. Is this default behavior for Firefox? Is this the same in IE as well?


use $el.position().left; instead :)


I do not believe that there are any known differences for positioning with jQuery as of the latest version 1.4.4.


I have used a plugin in the past: http://plugins.jquery.com/project/dimensions


The css () function returns the value of the specified css property as reported by the browser. As a result, it's browser specific and shouldn't be used when dealing with lengths and positioning in this way.


I worked around this issue by accessing DOM directly, like this:

$el.get(0).style.left

it returns the % value for FF, Chrome, Safari and IE9. (Didn't test it on Opera, though)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜