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 页面滚动光标不跟随 #29

Closed
Dream4ever opened this issue Jun 2, 2018 · 0 comments
Closed

iOS 页面滚动光标不跟随 #29

Dream4ever opened this issue Jun 2, 2018 · 0 comments
Labels
Front-end Everything you see and experience JS Javascript UI Nice to meet you

Comments

@Dream4ever
Copy link
Owner

需求描述

编写的网页出现了一个小 bug,滚动页面时,input 元素中的光标没有随着元素一起移动。

方案调研

调研过程

先是 Google: js after scroll cursor position,没有找到有用的结果。

因为该问题只在 iOS 上出现,所以调整 Google 关键字为:js iOS cursor page scroll。在 Blinking caret/cursor doesn't scroll with it's Input text form element #178 中给出了解决方案:页面滚动前让元素失去焦点,滚动后恢复焦点。

继续搜索,这次尝试中文关键字:iOS 表单元素 页面滚动 光标,给出的结果和英文的一样,都是滚动前失去焦点,滚动后恢复焦点。

入选方案

应用过程

示例代码:

let element = document.querySelector('#app');
element.blur();
element.scrollTop = 100;
element.focus();

要点总结

用对关键字也是很重要的搜索能力。

@Dream4ever Dream4ever added Front-end Everything you see and experience JS Javascript Webpage UI Nice to meet you labels Jun 2, 2018
@Dream4ever Dream4ever removed the Webpage label Jun 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Front-end Everything you see and experience JS Javascript UI Nice to meet you
Projects
None yet
Development

No branches or pull requests

1 participant