How to wait for the 'end' of 'resize' event and only then perform an action?

后端 未结 24 1222
深忆病人
深忆病人 2020-11-22 09:39

So I currently use something like:

$(window).resize(function(){resizedw();});

But this gets called many times while resizing process goes o

24条回答
  •  死守一世寂寞
    2020-11-22 10:10

    You can use setTimeout() and clearTimeout()

    function resizedw(){
        // Haven't resized in 100ms!
    }
    
    var doit;
    window.onresize = function(){
      clearTimeout(doit);
      doit = setTimeout(resizedw, 100);
    };
    

    Code example on jsfiddle.

提交回复
热议问题