jQuery resize() using browser maximise button

前端 未结 7 1506
礼貌的吻别
礼貌的吻别 2021-02-07 11:29

This is my code that fires whenever the window is resized:

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

Fires fine when I re

7条回答
  •  盖世英雄少女心
    2021-02-07 11:34

    var window_width_check_big = false, // flag true if window bigger than my_width
    window_width_check_small = false,   // flag true if window smaller than my_width
    my_width = 1221; // Change to your width
    
    function get_window_size() {
        if(window.innerWidth > my_width) {
            window_width_check_big = true;
        }
        if(window.innerWidth < my_width) {
            window_width_check_small = true;
        }   
    }
    
    get_window_size();
    
    $(window).resize(function() {
    
        if(window.innerWidth > my_width) {
            window_width_check_big = true;
        }
        if(window.innerWidth < my_width) {
            window_width_check_small = true;
        }
        if( window_width_check_small && window_width_check_big ) {
            window_width_check_big = false;
            window_width_check_small = false;
            get_window_size();
            // Start function that you need
        }
    });
    

提交回复
热议问题