Skip to content

Instantly share code, notes, and snippets.

@lilumi
Created January 24, 2021 13:00
Show Gist options
  • Save lilumi/928db025d3e3db26892e505d3c4b48e6 to your computer and use it in GitHub Desktop.
Save lilumi/928db025d3e3db26892e505d3c4b48e6 to your computer and use it in GitHub Desktop.
(function() {
var throttle = function(type, name, obj) {
obj = obj || window;
var running = false;
var func = function() {
if (running) { return; }
running = true;
requestAnimationFrame(function() {
obj.dispatchEvent(new CustomEvent(name));
running = false;
});
};
obj.addEventListener(type, func);
};
/* init - you can init any event */
throttle("resize", "optimizedResize");
})();
// handle optimizedResize event
window.addEventListener("optimizedResize", function() {
//do payload
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment