我在下面有这个示例图片。我只想在侧边栏部分选中时向上/向下滚动禁用。可以吗?任何帮助都将非常感激。
答案 0 :(得分:1)
谢谢你们......已经找到了解决方案。在这个例子http://jsbin.com/disable-scrolling/1上,我只是将点击功能转换为鼠标输入/离开。对于那些有同样问题的人,我会在下面提供代码。
document.getElementById("enable").onclick = function () {
enable_scroll();
document.getElementById("status").innerHTML = "enabled";
document.getElementById("status").className = "enabled";
};
document.getElementById("disable").onclick = function () {
disable_scroll();
document.getElementById("status").innerHTML = "disabled";
document.getElementById("status").className = "disabled";
};
// left: 37, up: 38, right: 39, down: 40,
// spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: 36
var keys = [37, 38, 39, 40];
function preventDefault(e) {
e = e || window.event;
if (e.preventDefault) e.preventDefault();
e.returnValue = false;
}
function keydown(e) {
for (var i = keys.length; i--;) {
if (e.keyCode === keys[i]) {
preventDefault(e);
return;
}
}
}
function wheel(e) {
preventDefault(e);
}
function disable_scroll() {
if (window.addEventListener) {
window.addEventListener('DOMMouseScroll', wheel, false);
}
window.onmousewheel = document.onmousewheel = wheel;
document.onkeydown = keydown;
}
function enable_scroll() {
if (window.removeEventListener) {
window.removeEventListener('DOMMouseScroll', wheel, false);
}
window.onmousewheel = document.onmousewheel = document.onkeydown = null;
}