Which is faster? - modifying css property or adding class in jquery

前端 未结 4 1809
暗喜
暗喜 2021-01-21 00:17

I have about 100 elements in like and am trying to create an animation with jquery.

I need to a

4条回答
  •  走了就别回头了
    2021-01-21 00:32

    Adding a class to the parent of all these 100 elements will be faster and defining that class in the css file or page.

    .style1 .box{
       //define style here
    }
    

    This way you just have to manipulate the class of only one element and it is definitely faster than modifying each of the 100 element's style using css method.

    How fast? It all depends on the number of lines of code executed in each of the operations which is again dependent on browser to browser.

    If you go with my approach it will definitely be faster.

提交回复
热议问题