Last active
August 29, 2015 14:15
-
-
Save baldore/fd13b75f4ff3085b93fe to your computer and use it in GitHub Desktop.
End Resize
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
app.service('$customEvents', function () { | |
/** | |
* Calls a function when the user ends the resize of the window | |
* | |
* @param callback {function} Function to call on the end of the resize | |
* @param _duration {number} Duration in milliseconds | |
*/ | |
this.onEndResize = function (callback, _duration) { | |
var time, | |
duration = typeof _duration !== "undefined" ? _duration : 180; | |
// callback must be function and duration integer | |
if (typeof callback !== "function" || duration >>> 0 !== parseFloat(duration)) return false; | |
window.addEventListener('resize', function () { | |
clearTimeout(time); | |
time = setTimeout(callback, duration); | |
}); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment