js to determine whether the soft keyboard is enabled to pop up

Regarding the page layout on the mobile side, if there is a box with position:fixed at the bottom and there is an input, the page layout will be affected when the soft keyboard pops up and closes. At this time, Android can listen to the resize event, the code is as follows, and ios has no related events .

var winHeight = $(window).height();    // Get the current page height 
$(window).resize( function (){
    var thisHeight=$( this ).height();
     if (winHeight - thisHeight >50 ){
          // When the soft keyboard pops up, operate here 

    } else {
         // When the soft keyboard is closed, operate here

    }
});
Solve the ios keyboard pop-up blocking input
function iosInput() {
    if(isIos()){
        $( '.chart-footer').css('position','absolute' );
         // Solve the problem that the bottom input box is blocked when the third-party soft keyboard is evoked 
        var bfscrolltop = document.body.scrollTop; // Get the soft The height of the scrolling part of the browser before the keyboard is evoked 
        $(".chart-input").focus( function (){ // here 'input.inputframe' is the input frame of my bottom input bar, fired when it gets focus Event 
            interval = setInterval( function (){ // Set a timer, the time setting is similar to the time required for the soft keyboard to pop up 
                document.body.scrollTop = document.body.scrollHeight; //After getting the focus, the height of all content in the browser will be set Give the browser scroll part height 
            },100 )
        }).blur( function (){ // Set the event when the input box loses focus 
            clearInterval(interval); // Clear the timer 
            document.body.scrollTop = bfscrolltop;
             // The scroll part of the browser before the soft keyboard is awakened The height is reassigned to the changed height 
        });
    }
}
iosInput();

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324932456&siteId=291194637