Created
November 30, 2014 15:22
-
-
Save RyoSugimoto/ab4b142d1aab0ba17a42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var throttle = (function () { | |
var interval = 500; // 間引き間隔 | |
var lastTime = new Date().getTime() - interval; | |
return function () { | |
// 最後に実行した時間から間引きしたい時間が経過していたら実行 | |
if ((lastTime + interval) <= new Date().getTime()) { | |
lastTime = new Date().getTime(); | |
// 処理 | |
} | |
}; | |
}()); | |
var debounce = (function () { | |
var interval = 500; | |
var timer; | |
return function () { | |
clearTimeout(timer); | |
timer = setTimeout(function () { | |
// 処理 | |
}, interval) | |
}; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment