【发布时间】:2019-02-03 20:02:52
【问题描述】:
我在另一个 div 内有一个 div,并应用了变换比例。
应用比例后,我需要获取此 div 的宽度。 .width() 的结果是元素的原始宽度。
请查看此代码笔: https://codepen.io/anon/pen/ZMpBMP
问题图片:
希望这足够清楚,谢谢。代码如下:
HTML
<div class="outer">
<div class="inner">
</div>
</div>
CSS
.outer {
height: 250px;
width: 250px;
background-color: red;
position: relative;
overflow: hidden;
}
.inner {
background-color: green;
height: 10px;
width: 10px;
transform: translate(-50%);
position: absolute;
top: 50%;
left: 50%;
transform: scale(13.0);
}
JS
$(function() {
var width = $('.inner').width();
// I expect 130px but it returns 10px
//
// I.e. It ignores the zoom/scale
// when considering the width
console.log( width );
});
【问题讨论】:
标签: javascript jquery html css scale