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

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

    var flag=true;
    var timeloop;
    
    $(window).resize(function(){
        rtime=new Date();
        if(flag){
            flag=false;
            timeloop=setInterval(function(){
                if(new Date()-rtime>100)
                    myAction();
            },100);
        }
    })
    function myAction(){
        clearInterval(timeloop);
        flag=true;
        //any other code...
    }
    

提交回复
热议问题