简体   繁体   English

Jquery对话框与空格键上的滚动

[英]Jquery dialog with scroll on space bar

We know that, the default functionality of a space bar in browser is to scroll to down if no input is active. 我们知道,如果没有输入处于活动状态,浏览器中空格键的默认功能是向下滚动。 similarly shift+space bar scroll top. 同样移位+空格键滚动顶部。

In my app, I'm using Jquery dialog on which if I press space bar when no input is active the background is scrolled instead of the dialog. 在我的应用程序中,我正在使用Jquery对话框,如果我在没有输入处于活动状态时按空格键,则滚动背景而不是对话框。

So, I added tabIndex = -1 which works fine when the dialog height is big (Means when the dialog has a scrollbar). 所以,我添加了tabIndex = -1 ,它在对话框高度很大时工作正常(表示对话框有滚动条时)。 But it is not working when the dialog has no scrollbar (Only the background is scrolling) 但是当对话框没有滚动条时(仅背景滚动)它不起作用

<div id="contactContainer" class="default-dialog" tabindex="-1"></div>

I don't want the user to prevent the space bar typing when no input is active. 当没有输入处于活动状态时,我不希望用户阻止空格键入。 The scrolling should work normal as I press the space bar. 当我按下空格键时,滚动应该正常。 If there is no scrollbar on the dialog, nothing should happen if I press the space bar. 如果对话框中没有滚动条,则按空格键时不会发生任何事情。

Is anybody faced the same situation? 有人面临同样的情况吗? Please give me a suggestion 请给我一个建议

The issue is, I've a container class which has some overflow elements. 问题是,我有一个容器类,它有一些溢出元素。 I did the following before I open the dialog 在打开对话框之前,我执行了以下操作

$('body, .container').addClass('overflow-hidden');

and I removed the class in the onClose event of the dialog 我在对话框的onClose事件中删除了该类

CSS: CSS:

.overflow-hidden { overflow: hidden}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM