防止使用箭头键滚动 [英] prevent scrolling with arrow keys

查看:26
本文介绍了防止使用箭头键滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果其中的 iframe 处于焦点状态,如何防止 html 页面在按下箭头键时滚动?

how can i prevent a html page from scrolling when arrow keys are pressed if a iframe inside it is focused?

我在 chrome 中遇到这个错误

im gettting this error in chrome

iframe 是有重点的,我知道它是有重点的.无论如何,父级都会滚动.

The iframe is focused, i know its focused. the parent scrolls anyway.

推荐答案

iframe 文档中的以下代码将阻止其滚动:

The following code inside the iframe document will prevent it from scrolling:

document.onkeydown = function(evt) {
    evt = evt || window.event;
    var keyCode = evt.keyCode;
    if (keyCode >= 37 && keyCode <= 40) {
        return false;
    }
};

这篇关于防止使用箭头键滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆