DOM onresize event

前端 未结 7 550
无人共我
无人共我 2020-12-02 19:06

If I have this

window.onresize = function() {
  alert(\'resized!!\');
};

My function gets fired multiple times throughout the res

7条回答
  •  温柔的废话
    2020-12-02 19:39

    simple pure javascript solution, just change the 1000 int value to be lower for more responsiveness

            var resizing = false;
            window.onresize = function() {
                if(resizing) return;
                console.log("resize");
                resizing = true;
                setTimeout(function() {resizing = false;}, 1000);
            };
    

提交回复
热议问题