jquery $('selector').css('top') returns different values for IE, firefox and Chrome

后端 未结 2 688
南笙
南笙 2021-01-22 05:14

I am using the jQuery $(\'selector\').css(\'top\') to get the top value to help position dynamic elements and I find that I get different results based on the browser.

i

2条回答
  •  粉色の甜心
    2021-01-22 05:31

    Use $('selector').offset().top to get the numeric value of the top position.
    .css() returns the CSS value of the top-position, which could be auto, 1234px, or something similar - not a reliable method to get the top position.

    See also:

    • http://api.jquery.com/offset/
    • http://api.jquery.com/position/

提交回复
热议问题