-
-
Save subimage/1ee189740e14bd75e0ed to your computer and use it in GitHub Desktop.
Simple jquery / underscore.js event handler for doing shit when the window resizes.
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 () { | |
var win, lazyResize; | |
function handleResize() { | |
var divWidth = $('#somediv').width(); | |
// now do something with that... | |
} | |
// debounce is an underscore.js function. | |
// We debounce so it doesn't fire too many times, taking up | |
// cycles on the user's computer. | |
lazyResize = _.debounce(handleResize, 100); | |
// Hold reference to window for speed. | |
win = $(window); | |
// Apply event handler on resizing window... | |
win.on('resize', lazyResize); | |
// Call it once to start | |
lazyResize(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment