Luk*_*kas 3 jquery scroll keypress
在keydown,按下按键后我有一些滚动动作.所以这就是它的样子:
$(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
}
});
Run Code Online (Sandbox Code Playgroud)
Everithing工作正常,但是当我滚动时,使用我的div按键也会整页滚动.有没有选择阻止这个身体滚动?
你需要.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);
}
});
Run Code Online (Sandbox Code Playgroud)