Skip to content

Instantly share code, notes, and snippets.

@amorkovin
Created August 25, 2020 08:54
Show Gist options
  • Save amorkovin/26b567e9ba8ab3c3bc5230c01d6a4e64 to your computer and use it in GitHub Desktop.
Save amorkovin/26b567e9ba8ab3c3bc5230c01d6a4e64 to your computer and use it in GitHub Desktop.
JavaScript ожидание загрузки и изменение ширины
// Ожидание полной загрузки страницы
window.addEventListener('load', function () {
});
// Прослушивание изменения ширины окна браузера https://developer.mozilla.org/ru/docs/Web/API/Window/resize_event
(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 event
window.addEventListener("optimizedResize", function() {
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment