Last active
April 27, 2017 03:16
-
-
Save Alex-xd/eaafda842d602b89147d6108e2576d4b to your computer and use it in GitHub Desktop.
This file contains 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
function debounce(dom, event, fn, timeout) { | |
var timeout = timeout || 3; // 默认延迟3s内点击无效 | |
var timer = null; | |
// cornor cases | |
if (!dom || !event || !(event in dom) || typeof fn !== 'function') { | |
return | |
} | |
dom.addEventListener(event, function () { | |
var _this = this; | |
clearTimeout(timer); | |
timer = setTimeout(function () { | |
fn.apply(_this) | |
}, timeout) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment