JavaScript/JQuery: $(window).resize how to fire AFTER the resize is completed?

前端 未结 12 863
终归单人心
终归单人心 2020-11-22 08:54

I\'m using JQuery as such:

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

However, it appears that if the person manually resizes their browser wind

12条回答
  •  深忆病人
    2020-11-22 09:23

    Assuming that the mouse cursor should return to the document after window resize, we can create a callback-like behavior with onmouseover event. Don't forget that this solution may not work for touch-enabled screens as expected.

    var resizeTimer;
    var resized = false;
    $(window).resize(function() {
       clearTimeout(resizeTimer);
       resizeTimer = setTimeout(function() {
           if(!resized) {
               resized = true;
               $(document).mouseover(function() {
                   resized = false;
                   // do something here
                   $(this).unbind("mouseover");
               })
           }
        }, 500);
    });
    

提交回复
热议问题