[TOC]java
移动web页面,input获取焦点弹出系统虚拟键盘时,偶尔会出现挡住input的状况,尽管几率不大,可是十分影响用户体验。git
element.scrollIntoView(alignToTop);
alignToTopgithub
Boolean
web
true
,元素的顶端将和其所在滚动区的可视区域的顶端对齐。false,
元素的底端将和其所在滚动区的可视区域的底端对齐。Element.scrollIntoViewIfNeeded(opt_center)
opt_centerthis
Boolean
默认true
code
推荐使用 scrollIntoViewIfNeeded
element
代码实例get
$('input').on('click', function () { var target = this; // 使用定时器是为了让输入框上滑时更加天然 setTimeout(function(){ // target.scrollIntoView(true); target.scrollIntoViewIfNeeded(true); // 推荐使用 },100); });
参考:input