使用jQuery键按下后,Body停止滚动

使用jQuery键按下后,Body停止滚动,jquery,scroll,keypress,Jquery,Scroll,Keypress,我有一些滚动动作后,按键,按下。这就是它看起来的样子: $(document).keydown(function(e) { e.stopPropagation(); if (e.keyCode === 40) { // some scrolling actions in specifie div } else if (e.keyCode === 38) { // some scrolling actions in specifie div

我有一些滚动动作后,按键,按下。这就是它看起来的样子:

$(document).keydown(function(e) {
    e.stopPropagation();

    if (e.keyCode === 40) {
        // some scrolling actions in specifie div
    } else if (e.keyCode === 38) {
        // some scrolling actions in specifie div
    }
});

一切正常,但当我滚动时,用我的div键也会滚动整个页面。是否有任何选项可以停止此正文滚动

如果您的身体当前有滚动动画,请使用
stop()


您需要
.preventDefault()
在其中

$(document).keydown(function(e) {
    e.stopPropagation();
    if (e.keyCode === 40) {
        e.preventDefault();
        console.log(40);
    } else if (e.keyCode === 38) {
        e.preventDefault();
        console.log(38);
    }
});

您可以发布一个JSFIDLE.net示例吗?它不是动画,而是在页面上按向上或向下键的默认行为。
$(document).keydown(function(e) {
    e.stopPropagation();
    if (e.keyCode === 40) {
        e.preventDefault();
        console.log(40);
    } else if (e.keyCode === 38) {
        e.preventDefault();
        console.log(38);
    }
});