jQuery样式未在Safari中应用 [英] jQuery style not being applied in Safari

查看:129
本文介绍了jQuery样式未在Safari中应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绝对定位的元素,我移动与jQuery的帮助下使用CSS正常左。

I have an absolutely positioned element that I move with the help of jQuery using the CSS propertly 'left'.

$("#element").css('left', '103px');

在Firefox中,这是正常工作。但在Safari中,我可以看到风格出现在Web Inspector的element.style下,但风格没有更新。如果我禁用(并重新启用)任何匹配的CSS规则(即使那些不直接应用于我的div),应用于jQuery的样式被呈现。

In Firefox this works as expected. However in Safari I can see the style appearing in the Web Inspector under element.style, but the style isn't updated. If I disable (and re-enable) any matched CSS-rules (even those not applied directly to my div) the style being applied with jQuery is rendered.

我在旧的PowerMac上使用jQuery 1.7.2运行Safari 5.0.6。

I'm running Safari 5.0.6 on an old PowerMac, with jQuery 1.7.2.

推荐答案

我遇到了这个问题一次,我最后使用addClass和removeClass元素父容器。

I faced this problem once and i end up using addClass and removeClass on elements parent container.

请尝试此

$("#element").css('left', '103px').parent().addClass("dummyClass").removeClass("dummyClass");

如果这不起作用,则可以肯定。

if that doesn't work follwoing will work for sure.

$("#element").css('left', '103px');
$("body").addClass("dummyClass").removeClass("dummyClass");

问题是,有时候Safari浏览器不会重绘页面,当我们改变CSS,所以我们需要强制重画

the problem is sometime safari doesn't redraw the page when we change CSS so we need to force redrawing

这篇关于jQuery样式未在Safari中应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆