Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ios手机调起键盘后,整个页面被顶上去了,关闭后仍然在上面,底部有一块空白 #15

Open
milixie opened this issue Dec 31, 2019 · 0 comments

Comments

@milixie
Copy link
Owner

milixie commented Dec 31, 2019

问题描述:
ios手机,点击输入框调起键盘后,整个页面被顶上去了,关闭弹窗后页面还是没有下来,导致下面有一大块空白,但是手动滚动一下就好了,怎么办?

首先,我尝试监听了键盘的blur事件,在键盘blur后去调用一下滚动,代码如下:
window.scrollTo(0, document.documentElement.scrollTop || document.body.scrollTop )

结果发现:
有时候生效有时候不生效

于是对该方法做了改进:加了延时并且少滚动一像素,发现成功解决了这个问题,完美

setTimeout(() => {
      const scrollH = document.documentElement.scrollTop || document.body.scrollTop
          window.scrollTo(0, Math.max(scrollH - 1, 0) )
        }, 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant