admin管理员组文章数量:1357307
In Firefox, I need to scale a <div>
containing text and images.
After using -moz-transform: scale()
the content is visually scaled but the <div>
still returns it's original sizes when trying to get these values using javascript.
Any solution for this behaviour?
In Firefox, I need to scale a <div>
containing text and images.
After using -moz-transform: scale()
the content is visually scaled but the <div>
still returns it's original sizes when trying to get these values using javascript.
Any solution for this behaviour?
Share Improve this question edited Dec 9, 2011 at 13:56 Pierre 19.1k5 gold badges43 silver badges62 bronze badges asked Dec 9, 2011 at 12:45 galer88galer88 2404 silver badges15 bronze badges 1- 1 Could you give a piece of code to reproduce what you do? And I guess you've had a look at the pages reended here: stackoverflow./questions/4049342/… – Nikodemus RIP Commented Dec 9, 2011 at 12:55
3 Answers
Reset to default 4If you already know the scale value, do the math using a bit of javascript. Multiply the scale value by the actual sizes you are getting. (960px scaled to 0.5 = 480px)
If you don't know the scale value, you need to get the current transformation matrix using getComputedStyle()
and then do the math.
var element = document.getElementById("divScaledToHalf"),
style = window.getComputedStyle(element, ""),
matrix = style.getPropertyValue("-moz-transform");
console.log(matrix); // matrix(0.5, 0, 0, 0.5, 0px, 0px)
Use element.getBoundingClientRect()
its already answered here:
CSS3 how to calculate height and width after scale
When galer88 says:
"After using -moz-transform: scale() the content is visually scaled but the <div> still returns it's original sizes when trying to get these values using javascript."
The DIV's original sizes are being returned because in fact what is really happening is a ZOOM and not a SCALE.
When you SCALE an object, you should literally modify the width, height, and depth (in case of 3D) of the object to make it smaller or larger.
When you ZOOM out or in, on the other hand, you simply move the camera's focus further back or nearer to the object. The object's width, height, and depth (in case of 3D) are not affected during zooming.
Please check a possible solution in Pierre's answer.
本文标签: javascriptGet actual width and height of an element after being scaled using CSS3Stack Overflow
版权声明:本文标题:javascript - Get actual width and height of an element after being scaled using CSS3 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744028992a2578563.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论