Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
473 views
in Technique[技术] by (71.8m points)

css - jQuery style not being applied in Safari

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

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

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

try this

$("#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");

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...