我在按下按键、按键后有一些滚动动作。这就是它的样子:
$(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 按键也会滚动整个页面。有什么选项可以停止这个身体滚动吗?
你需要.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);
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)