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);
}
'웹' 카테고리의 다른 글
중앙 집중형 타이머 관리 (0) | 2018.09.18 |
---|---|
javascript DOM tree 를 node 기준으로 split 하기 (0) | 2018.05.04 |
javascript 요소 크기 (element offset / client / scroll ) (0) | 2018.05.01 |
javascript contains() method (0) | 2018.05.01 |