1

Is it possible to get the actual height of a element that has been scaled with

transform: scale(...);

I have tried the following, but they are returning the original height

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

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

Demo: http://jsfiddle.net/ZvzXJ/

iConnor
  • 19,997
  • 14
  • 62
  • 97

2 Answers2

10

After a while, i have found the solution to this

You have to use

Element.getBoundingClientRect();

Like so

$('element')[0].getBoundingClientRect().height;
iConnor
  • 19,997
  • 14
  • 62
  • 97
-1

Use below code to Get actual height of scaled transformed element. [jsFiddle]

user 'outerHeight' instead of '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>
Vipul Vaghasiya
  • 481
  • 1
  • 5
  • 16