https://developer.mozilla.org/zh-CN/docs/Web/API/Window/resize_event

    1. ;(function() {
    2. var throttle = function(type, name, obj) {
    3. obj = obj || window;
    4. var running = false;
    5. var func = function() {
    6. if (running) { return; }
    7. running = true;
    8. requestAnimationFrame(function() {
    9. obj.dispatchEvent(new CustomEvent(name));
    10. running = false;
    11. });
    12. };
    13. obj.addEventListener(type, func);
    14. };
    15. /* init - you can init any event */
    16. throttle("resize", "optimizedResize");
    17. })();
    18. // handle event
    19. window.addEventListener("optimizedResize", function() {
    20. console.log("Resource conscious resize callback!");
    21. });