Created
August 25, 2020 08:54
-
-
Save amorkovin/26b567e9ba8ab3c3bc5230c01d6a4e64 to your computer and use it in GitHub Desktop.
JavaScript ожидание загрузки и изменение ширины
This file contains hidden or 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
// Ожидание полной загрузки страницы | |
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