How to get new position after transform div jquery

2019-09-21 05:31发布

How to get new position after transform? Can anybody please help me to do that.

I used

$('#text').css('-moz-transform','rotate(90deg)');

Now I want to get left and right postion.

When I try to get left and top position it shows left and top position before transform

$('#text').position().left;    
$('#text').position().top;

It shows position before div transform

I want to get the new position. How do i do that?

2条回答
唯我独甜
2楼-- · 2019-09-21 06:08

I am trying to solve this issue as well. What the user is saying is this:

Let's say you have a div that is 300px by 200px and the top and left position is: 100, 100.

If you rotate it from the center, the top and left positions of the div has now changed, yet Mozilla still returns the pre-rotated top/left positions. Chrome actually returns the correct values after rotation, but FireFox does not.

If you inspect the element with FireBug, the highlighted area is the div also pre-rotation. So there doesn't appear to be any normal way to get the top and left positions after rotating, unless there is some kind of formula that could calculate it based on the height and width and the angle.

Does anyone know of such a formula, or another way to solve this issue?

查看更多
ゆ 、 Hurt°
3楼-- · 2019-09-21 06:08
console.log($('#text').offset().left);
console.log($('#text').offset().top);

I've got the same result as in Chrome as in Firefox

查看更多
登录 后发表回答