输入框被虚拟键盘挡住问题

输入框被虚拟键盘挡住问题

1.问题所在:当虚拟键盘弹出时把输入框给挡住了

解决方法一:
使用方法api: scrollIntoView
说明:让元素跳到页面可视区去

元素.scrollIntoView()
document.querySelector('类').scrollIntoView()

传值:
两种: 1.boolean   true和false  意思: 元素跳顶部和底部
	  2.object 		{
	  			block: start和end,
	  			behavior: smooth(动画)和 instant 和 auto  注:后两是没动画的
				}

解决方法二:
使用方法api:scrollIntoViewIfNeeded
说明: scrollIntoView的变体,和scrollIntoView的区别在于 1.在可视区时,元素的位置是不会有变动的 2.如被遮盖会跳到可视区的中间(不像scrollIntoView跳顶部和底部)

元素.scrollIntoView()
document.querySelector('类').scrollIntoViewIfNeeded()
传值
一种: 1. boolean  true(默认值,居中)和 false(时元素可能顶部或底部对齐,视乎元素靠哪边更近)

最后: 更详细的信息可看MDN scrollIntoView的MDN链接

Guess you like

Origin blog.csdn.net/Object_prototype/article/details/112767141