How to determine if a resize event was triggered by soft keyboard in mobile browser?

前端 未结 8 1696
一向
一向 2020-12-29 21:03

There\'s a lot of discussion about the soft keyboard but I haven\'t found a good solution for my problem yet.

I have a resize function like:

$(window         


        
8条回答
  •  自闭症患者
    2020-12-29 21:25

    I've been looking for a solution to a similar issue. My resize event was triggering when the url input came in and out of view. This is something I've been working on... Could have a possible solution?

    So basically you just check if the width of the screen alone has changed or not, and only fire your functions on the resize if it is different:

    eg:

    var saveWindowWidth = true;
        var savedWindowWidth;
    
    //set the initial window width
        if (saveWindowWidth = true){
            savedWindowWidth = windowWidth;
            saveWindowWidth = false;
        }
    
    
    //then on resize...
    
    
    $(window).resize(function() {
    
    //if the screen has resized then the window width variable will update
            windowWidth = window.innerWidth;
    
    
    //if the saved window width is still equal to the current window width do nothing
            if (savedWindowWidth == windowWidth){
                return;
            }
    
    
    //if saved window width not equal to the current window width do something
            if(savedWindowWidth != windowWidth) {
               // do something
    
                savedWindowWidth = windowWidth;
            }
    
        });
    

提交回复
热议问题