【发布时间】:2019-11-18 19:09:48
【问题描述】:
我有一个输入,下面有一张地图: 使用地图输入
问题是当我将输入集中在手机上时,键盘弹出并且输入消失了。 我试图在键盘弹出后将页面滚动到输入可见的位置,但在 Android 上的 Chrome 中 $(window).scrollTop(value) 不起作用。我是这样使用的:
$shopListSearch.on('focus', function() {
let
$this = $(this),
thisHeight = $this.innerHeight(),
value = thisOffsetTop - thisHeight - $header.innerHeight();
//timeout to wait while keyboard pops up
setTimeout(function() {
$window.scrollTop(value);
}, 2000);
});
这适用于移动设备的Chrome模拟器,但不适用于真正的Android手机。我该怎么做才能让它在手机上运行?
【问题讨论】:
-
value变量应该是$this.offset().top - $header.innerHeight();。如果你减去thisHeight,它就会超出窗口视图。尝试使用var而不是let进行良好实践。因为let(ES6) 兼容现代浏览器。当var几乎兼容所有浏览器时。 -
问题是$window.scrollTop(value)在Android手机上什么都不做,不是滚动值不对。而且我使用转译器,所以“let”会自动转译为 var。
标签: javascript jquery