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

前端 未结 4 1845
暗喜
暗喜 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:31

    According to jsPerf, addClass is noticeably faster by about 50%.

    Here's the jsPerf data for Chrome but in my tests it was about the same using Firefox:

    $('#a1').css({ 'background-color': '#000' }) 82,043 ±0.21% 48% slower

    $('#a1').addClass("style1") 158,876 ±0.83% fastest

提交回复
热议问题