Skip to content

Instantly share code, notes, and snippets.

@baldore
Last active August 29, 2015 14:15
Show Gist options
  • Save baldore/fd13b75f4ff3085b93fe to your computer and use it in GitHub Desktop.
Save baldore/fd13b75f4ff3085b93fe to your computer and use it in GitHub Desktop.
End Resize
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