getting percent CSS position with jQuery

后端 未结 7 871
终归单人心
终归单人心 2021-02-13 19:05

I\'m trying to get an element\'s CSS (top and left) with jQuery:

$(element).css(\'top\');

but instead of \"12%\" like it should be, I get the p

7条回答
  •  一个人的身影
    2021-02-13 19:12

    You can do this:

    $(element).position().top / $(element).parent().height() * 100
    

    Regarding your precedent comment, if you want to work with css('top'), don't forget to parseInt it.

提交回复
热议问题