cssText or individual stylename?

社会主义新天地 提交于 2019-12-08 16:49:03

问题


When we are applying a lot of style changes using JavaScript to a single element, phpied & Writing Efficient JavaScript (slide 87) suggests:

instead of applying styles one by one using style.stylename, apply everything in one go using cssText or changing classname as it'll reduce reflows/repaints

Which is better when there's only a single style change?

document.getElementById('myid').style.cssText += ";color:#999;";

OR

document.getElementById('myid').style.color = "#999";

jsperf.com/csstext-vs-styles-single shows that when there's only a single style change, using individual style name is faster than cssText.

Are there any other factors also to be considered?


回答1:


I should use the individual stylename in your case, because you are going to change only one style. :)



来源:https://stackoverflow.com/questions/6254412/csstext-or-individual-stylename

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!