함수 감속

2018. 8. 7. 00:25

1. 함수 감속

function throttle(method, context) {

clearTimeout(method.tId);

method.tId = setTimeout(function() {

method.call(context);

}, 100);

}

 

사용 예제)

window.onresize = function() {

var div = document.getElementById("myDiv");

div.style.height = div.offsetWidth + "px";

};


->


function resizeDiv() {

var div = document.getElementById("myDiv");

div.style.height = div.offsetWidth + "px";

};


window.onresize = function {

throttle(resizeDiv);

}

Posted by 창의력대장3
,