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

后端 未结 24 1130
深忆病人
深忆病人 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:25

    var resizeTimer;
    $( window ).resize(function() {
        if(resizeTimer){
            clearTimeout(resizeTimer);
        }
        resizeTimer = setTimeout(function() {
            //your code here
            resizeTimer = null;
            }, 200);
        });
    

    This worked for what I was trying to do in chrome. This won't fire the callback until 200ms after last resize event.

提交回复
热议问题