charling

当为窗口绑定resize事件时,大部分浏览器会在每改变一个像素就触发一次resize事件。这严重影响了网站的性能。

解决方案是:利用settimeout方法为事件发触发的方法设置延迟执行的时间。

实现:

  function lazyScroll( method, context, delay ){

    clearTimeout( method.tId );

    method.tId = setTimeout( function(){

      method.call( context );

    },delay );

  }

  function doSomething(){alert(1);}

  lazyScroll( doSomething, window, 500);

分类:

技术点:

相关文章:

  • 2021-09-26
  • 2021-07-16
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2022-01-02
  • 2021-10-11
猜你喜欢
  • 2021-12-15
  • 2021-11-23
  • 2021-06-26
  • 2022-01-17
  • 2022-12-23
  • 2021-11-17
  • 2021-05-18
相关资源
相似解决方案