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

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

    I don't know is my code work for other but it's really do a great job for me. I got this idea by analyzing Dolan Antenucci code because his version is not work for me and I really hope it'll be helpful to someone.

    var tranStatus = false;
    $(window).resizeend(200, function(){
        $(".cat-name, .category").removeAttr("style");
        //clearTimeout(homeResize);
        $("*").one("webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend",function(event) {
          tranStatus = true;
        });
        processResize();
    });
    
    function processResize(){
      homeResize = setInterval(function(){
        if(tranStatus===false){
            console.log("not yet");
            $("*").one("webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend",function(event) {
                tranStatus = true;
            }); 
        }else{
            text_height();
            clearInterval(homeResize);
        }
      },200);
    }
    

提交回复
热议问题