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

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

    Well, as far as the window manager is concerned, each resize event is its own message, with a distinct beginning and end, so technically, every time the window is resized, it is the end.

    Having said that, maybe you want to set a delay to your continuation? Here's an example.

    var t = -1;
    function doResize()
    {
        document.write('resize');
    }
    $(document).ready(function(){
        $(window).resize(function(){
            clearTimeout(t);
            t = setTimeout(doResize, 1000);
        });
    });
    

提交回复
热议问题