Yuj*_* Wu 5 firefox jquery cross-browser
使用下面的标记和CSS,我试图获得计算的shell左边距.
<section class="page-title">
<div class="shell">
<h5 class="title">Welcome!</h5>
</div>
</section>
.shell {
zoom: 1;
max-width: 1000px;
margin-left: auto;
margin-right: auto;
padding-left: 16px;
padding-right: 16px;
}
Run Code Online (Sandbox Code Playgroud)
运用
parseInt($('.shell').css('marginLeft'))
Run Code Online (Sandbox Code Playgroud)
它适用于Chrome,Safari,IE9,但令人惊讶的是在Firefox中不起作用.尝试了另一种方法:
($('.shell').outerWidth(true) - $('.shell').outerWidth()) / 2
Run Code Online (Sandbox Code Playgroud)
同样适用但Firefox.所以我猜火狐不支持用jQuery获取未定义的CSS?解决这个问题的直接方法是:
($('.page-title').width() - $('.shell').outerWidth()) / 2
Run Code Online (Sandbox Code Playgroud)
但我想知道是否有更好的方法.