函数节流

function throttle(method, context) {
  clearTimeout(method.tId);
  method.tId = setTimeout(function () {
    method.call(context);
  }, 100);
}
function resizeDiv() {
  var div = document.getElementById("myDiv");
  div.style.height = div.offsetWidth + "px";
}
window.onresize = function () {
  throttle(resizeDiv);
};

  

posted @ 2019-09-25 19:38  寒筱洱  阅读(100)  评论(0编辑  收藏  举报