在更改完全应用之前,jQuery的css方法是否会阻塞? [英] Does jQuery's css method block until the change is fully applied?

查看:37
本文介绍了在更改完全应用之前,jQuery的css方法是否会阻塞?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用jQuery的 css 函数应用CSS更改后,我想执行一些计算.这种方法是否要等到CSS更改完全应用并完成要重新绘制的元素之后?

I've got some computation that I want to execute after a CSS change is applied using jQuery's css function. Does this method wait until the CSS change is completely applied, complete with the element being repainted?

推荐答案

使用JavaScript修改样式是一种同步行为.更新元素的类,ID和内联样式将立即对该元素生效,并且您可以安全地获取该元素的新尺寸或样式.

Modifying styles with JavaScript is a synchronous behavior. Updating classes, IDs, and inline styles of elements will immediately take effect on the element, and you can safely grab the new dimensions or styles of that element.

话虽如此,但在各种浏览器中都有一些 niche bug ,除非非常特殊的样式,否则它们不会重绘进行更改.同样,布局的重新计算是同步进行的,但是您可能需要做一些额外的工作才能强制进行重新绘制.

With that said, there are a few niche bugs in various browsers where repainting won't happen unless very specific style changes are made. Again, the recalculation of layout happens synchronously, but you may need to do additional work to force the repaint to happen.

这篇关于在更改完全应用之前,jQuery的css方法是否会阻塞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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