1

是否可以获得height已缩放元素的实际值

transform: scale(...);

我尝试了以下方法,但他们正在退回原件height

$('element').css('height');  // 16px (demo)

$('element').height(); // 21px (demo)

演示:http: //jsfiddle.net/ZvzXJ/

4

2 回答 2

10

一段时间后,我找到了解决方案

你必须使用

Element.getBoundingClientRect();

像这样

$('element')[0].getBoundingClientRect().height;
于 2013-08-05T09:49:19.343 回答
-1

使用下面的代码来获取缩放转换元素的实际高度。[ jsFiddle]

用户 'outerHeight' 而不是 'height'

http://jsfiddle.net/ZvzXJ/8/

//full code here

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>

<style>
.button{
    -webkit-transform: scale( 3 );
    margin:100px;
    display:block;
}
</style>

<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function($) {
    $(window).load(function(){
         alert($('.button').outerHeight()+ 'px');
         alert($('.button').css('height'));
    });   
});
</script>

</head>

<body>
<button class="button">Welcome</button>
</body>
</html>
于 2013-08-05T09:18:14.467 回答