防止窗口滚动jquery

防止窗口滚动jquery

本文介绍了防止窗口滚动jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在jquery中开发一个选择菜单替换。

首先,我只需要添加 tabindex =0到容器。

然后,我禁用原始选择菜单上的焦点并将焦点放在新的菜单上。
当新的一个被聚焦并且您按下向上和向下箭头时,选项会相应地改变,但是存在一个很大的问题。当你按下箭头时,身体也会移动。

到目前为止我尝试了所有这些解决方案而没有运气:

I'm developing a select menu replacement in jquery.
First I've to make the new select menu focusable by just adding tabindex="0" to the container.
Then, I disable focus on the original select menu and give focus to the new one.When the new one is focused and you press the up and down arrows the options change accordingly but there's a big problem. As you press the arrows the body moves too.
I tried all these solutions so far with no luck:

$(window).unbind('scroll');
$(document).unbind('scroll');
$('body').unbind('scroll');
$(window).unbind('keydown');
$(document).unbind('keydown');

检查此处的代码
此代码来自Ideal Forms的开发版,提供键盘支持。

Check the code here http://pastebin.com/pVNMqyuiThis code is from the development version of Ideal Forms http://code.google.com/p/idealforms that I'm about to release soon, with keyboard support.

为什么这不起作用的任何想法?

Any ideas why this is not working?

编辑:解决了!

在这篇文章中找到答案

Found the answer on this post jquery link tag enable disable

var disableScroll = function(e){
    if (e.keyCode === 40 || e.keyCode === 38) {
        e.preventDefault();
        return false;
    }
};
// And then...
events.focus: function(){ $(window).on('keydown', disableScroll); }
events.blur: function(){ $(window).off('keydown', disableScroll); }

一切正常!

推荐答案

在这篇文章中找到答案 jquery link tag enable disable

Found the answer on this post jquery link tag enable disable

var disableScroll = function(e){
    if (e.keyCode === 40 || e.keyCode === 38) {
        e.preventDefault();
        return false;
    }
};
// And then...
events.focus: function(){ $(window).on('keydown', disableScroll); }
events.blur: function(){ $(window).off('keydown', disableScroll); }

这篇关于防止窗口滚动jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 13:28