【问题标题】:How to Prevent Scrolling on mobile when you focus on a new input?当您专注于新输入时,如何防止在移动设备上滚动?
【发布时间】:2019-09-21 18:40:20
【问题描述】:

我正在使用 javascript focus() 函数自动从一个输入块跳转到下一个输入块。不幸的是,在移动 chrome 上,每次调用 focus() 函数时,chrome 都会决定闪烁或抽搐以重新聚焦到下一个块。调用 focus() 时,有什么方法可以停止默认的重新聚焦/滚动行为?这是我在移动 chrome 上遇到的问题的 10 秒视频。 https://youtu.be/UmHJVxqrLS8

我认为这会起作用,但事实并非如此。

code[i + 1].focus({preventScroll: true});

这些答案也没有真正帮助我Preventing page from scrolling on focus switching

【问题讨论】:

    标签: javascript html input mobile scroll


    【解决方案1】:

    看看这个,相信它会对你有所帮助。

    https://codepen.io/wesleypimentel/pen/KpgXJW?editors=0010

    function keydown(e) {
    for (var i = keys.length; i--;) {
        if (e.keyCode === keys[i]) {
            preventDefault(e);
            return;
        }
    }
    

    }

    【讨论】:

      猜你喜欢
      • 2016-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-23
      • 2014-01-04
      • 1970-01-01
      相关资源
      最近更新 更多