getting percent CSS position with jQuery

后端 未结 7 851
终归单人心
终归单人心 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:25

    I just encountered this myself and thought it weird, too.

    Instead of:

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

    I just did:

     element.style.top
    

    No jQuery and gives you the actual value in the type you made it (percent, ems, etc.)

提交回复
热议问题