当页面方向改变时响应

Respond when page orientation change

本文关键字:响应 改变 方向      更新时间:2023-09-26

我已经有了下面的窗口大小调整函数。我的问题是我如何使它的工作在窗口调整大小以及页面方向改变?

    $(window).resize(function() {
        if(this.ab) clearTimeout(this.ab);
        this.ab = setTimeout(function() { 
            $(this).trigger('winresized');
        },1000);
    });
    $(window).on('winresized', function() {
    });

你可以同时使用resize和orientationchange事件:

$(window).on("resize orientationchange", function() {
    // Fires on both resize & orientation change
    if(this.ab) clearTimeout(this.ab);
    this.ab = setTimeout(function() { 
        $(this).trigger('winresized');
    },1000);
});