简体   繁体   English

在Webkit浏览器中使用jQuery获取CSS中的计算百分比值

[英]Get calculated percentage value in CSS using jQuery in Webkit browsers

I'm creating a simple sliding motion. 我正在创建一个简单的滑动动作。 But the div that is sliding in is using percentage for its width and right positioning. 但是滑入的div使用百分比表示其widthright位置。

The problem is in Webkit browsers. 问题出在Webkit浏览器中。 The value that I get using jQuery is actually the Percentage itself, while in Firefox, jQuery returned the calculated value of the percentage, based on the width of the parent element. 我使用jQuery所获得的值实际上是Percentage本身,而在Firefox中,jQuery根据父元素的width返回了百分比的计算值。

See here: http://jsfiddle.net/flisterz/ChZLu/ 看到这里: http : //jsfiddle.net/flisterz/ChZLu/

Click the trigger, and u can see the " right " value is the % value on your first click on Webkit (first click only). 单击触发器,然后您可以看到“ right ”值是您第一次单击Webkit时的%值(仅第一次单击)。 In Firefox, the " right " value is already the correctly calculated on even on first click. 在Firefox中,即使单击也可以正确计算出“ right ”值。

Any tips? 有小费吗? Thanks! 谢谢!

It might be that you have to get the position() . 可能是您必须获取position() Seeing as things are generally positioned top/left I've made the example use left rather than right. 鉴于事物通常位于顶部/左侧,因此我在示例中使用的是左而不是右。 It still is setup in css using percents. 它仍然是使用百分比在CSS中设置的。

A little more math and you can use right if you really need to. 多一点数学,如果您确实需要,可以使用正确的方法。

See: http://jsfiddle.net/ChZLu/1/ 请参阅: http//jsfiddle.net/ChZLu/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM