[英]Get height and width of a element after trasforming
我正在嘗試使用webkit或任何其他方法進行轉換/縮放后獲取HTML元素的大小。
放大后,該元素占用的像素比轉換前要多。
我嘗試過.height() .width() .offsetHeight() .clientHeight()
它們都在轉換元素后返回相同的值。
轉換后是否有辦法獲取元素的實際寬度和高度?
您可以使用getComputedStyle
在元素上獲取有效的樣式:
var matrix = new WebKitCSSMatrix(getComputedStyle($('#el')[0]).webkitTransform)
$('#el')
是您的元素。
然后matrix.a
和matrix.d
應該給出相關的比例因子。 之后,只需分別使用$('#el').width()*matrix.a
和$('#el').height()*matrix.d
嘗試outerHeight()
, outerWidth()
, outerHeight(true)
, outerWidth(true)
還可以嘗試在瀏覽器之前休息一下,方法是使用setTimout(function() { /* do you measuring here */ }, 0);
安排代碼,以setTimout(function() { /* do you measuring here */ }, 0);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.