Home  >  Q&A  >  body text

javascript - How to fix the input box of a mobile web page to the bottom?

As shown in the picture above, when the user clicks on the input box on the homepage, the keyboard pops up, and sometimes the input box is partially blocked (as shown below)

The current processing method is to execute resize

after the input box gains focus.
$('input').on('focus' , function(){
    $(window).resize();
}).on('blur' , function() {
    $(window).resize();
});

The purpose of this is to reset the window size and reposition the input box that originally floated at the bottom
But the effect is not very good, sometimes it takes effect and sometimes it fails

What method should be used to better handle this problem?
Also, while the keyboard pops up, scrolling the page can also keep the input area fixed at the bottom

The current positioning method of the input box is: position:fixed
Screenshot environment: ios WeChat

仅有的幸福仅有的幸福2674 days ago993

reply all(5)I'll reply

  • 阿神

    阿神2017-06-24 09:45:57

    Input box, you can use flex to fix it to the bottom. To fix flex to the bottom, you can check sticky-footer

    reply
    0
  • 怪我咯

    怪我咯2017-06-24 09:45:57

    It is recommended that you use js to calculate and use window.innerHeight

    reply
    0
  • 漂亮男人

    漂亮男人2017-06-24 09:45:57

    http://www.cnblogs.com/cococe...
    Try this

    reply
    0
  • 漂亮男人

    漂亮男人2017-06-24 09:45:57

    The person above is right, you can use flex. Those who advertise use this attribute. I think this can solve your problem

    reply
    0
  • PHP中文网

    PHP中文网2017-06-24 09:45:57

    Address: http://www.haorooms.com/post/...
    Principle: Don’t use fixed on ios, use absolute instead.
    End.

    reply
    0
  • Cancelreply