Created
May 16, 2021 10:59
-
-
Save alivelee/04562d046c08f7c37b88ea4aaa5eda00 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
const debounce = (fn, ms = 0) => { | |
let timeoutId; | |
return function(...args) { | |
clearTimeout(timeoutId); | |
timeoutId = setTimeout( | |
() => fn.apply(this, args), | |
ms | |
); | |
}; | |
}; | |
// 每250ms打印一次window尺寸 | |
window.addEventListener( | |
'resize', | |
debounce(() => { | |
console.log(window.innerWidth); | |
console.log(window.innerHeight); | |
}, 250) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment