javascript - 无法在 chrome 中使用键盘滚动页面

标签 javascript jquery html css google-chrome

我在我一直在工作的网站之一中发现了一个非常奇怪的问题,问题是关于使用 chrome 中的键盘从上/下滚动页面,这是我的结构 (JSFiddle demo)

在此页面中,我所做的更改是,通过对 html 和 body 执行 overflow:hidden 并在容器中启用滚动来重置 body 滚动。

当您在 chrome 中打开网站并且没有点击页面中的任何地方时,就会出现此问题,只需尝试使用键盘向下箭头进行滚动,但是当您点击页面上的任何地方时,这会正常工作。而且这个问题目前只在 chrome 中出现。

我该如何解决这个问题?记住相同的结构(不在 html/body 中启用溢出)

请帮忙!!

html, body {
	overflow: hidden;
	height: 100%;
	margin: 0;
	padding: 0;
}
.wrapper {
	width: 100%;
	float: left;
	overflow: auto;
	height: 100%;
}
<div class="wrapper">
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
  <p>Hello this is test</p>
</div>

最佳答案

你必须在 div 中添加一个 tabindex :

<div class="wrapper" tabindex="1">...

然后添加这个脚本:

document.getElementsByClassName("wrapper")[0].focus();

关于javascript - 无法在 chrome 中使用键盘滚动页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41263443/

相关文章:

javascript - 如何更改 EmberJS 关系的空值

javascript - Angular 发布到 ASP.NET Core Web API 返回失败

javascript - onbeforeunload 在所有浏览器中的无缝行为

c# - jQuery 表单提交函数中的 AJAX 调用

javascript - 为什么当我更改它们的源属性时我的图像没有改变 -JQuery Mobile & Phone Gap

javascript - HTML Javascript - 获取所有具有 ID 的元素

javascript - NodeJS 示例中奇怪的 JavaScript 语法

jquery - 为什么jqueryui.dialog选中的元素是表格时会忽略height参数?

javascript - 我的 JQuery 图像幻灯片似乎不起作用

jquery - 如何修复 toggleClass jQuery 不工作