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

前端 未结 12 840
终归单人心
终归单人心 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:48

    I prefer to create an event:

    $(window).bind('resizeEnd', function() {
        //do something, window hasn't changed size in 500ms
    });
    

    Here is how you create it:

     $(window).resize(function() {
            if(this.resizeTO) clearTimeout(this.resizeTO);
            this.resizeTO = setTimeout(function() {
                $(this).trigger('resizeEnd');
            }, 500);
        });
    

    You could have this in a global javascript file somewhere.

提交回复
热议问题