发布在:性能

使用样式表更改多个元素的 CSS

如果你使用 .css() 更改超过 20 个元素的 CSS,请考虑向页面添加样式标签,这样速度几乎可以提高 60%。

1
2
3
4
5
6
// Fine for up to 20 elements, slow after that:
$( "a.swedberg" ).css( "color", "#0769ad" );
// Much faster:
$( "<style type=\"text/css\">a.swedberg { color: #0769ad }</style>")
.appendTo( "head" );