jQuery animate() and browser performance

后端 未结 7 700
小蘑菇
小蘑菇 2020-12-03 09:48

I\'ve got some elements that I\'m moving across the page very slowly. Essentially, I\'m decreasing the left margin of two images over a span of 40 seconds or so.

Vi

7条回答
  •  独厮守ぢ
    2020-12-03 10:26

    jQuery animate uses the javascript function 'setInterval' to update the obects every few milliseconds. Unfortunately the interval in jQuery is per default '13ms'. Thats 76 updates every second. Way to much for such slow and medium animations.

    The 13ms are hardcoded into jQuery. So you can directly change this value in the jQuery.js, only. If you only have the slow clowds you can go up to 100ms. If you have some faster animations, too, you should set it to 50.

    You can change the parameter for setInterval(); in the function custom. 'jQuery.fx.prototype { ... custom: function() { ... } ... }'

提交回复
热议问题