是否可以允许单击但不允许滚动事件?

pointer-events: none;

将禁用两种类型的输入,我只想禁用滚动。还有其他解决方法的想法吗?

最佳答案

用javascript来做:

function noScroll(event) {
    event = event || window.event;
    if (event.preventDefault) {
        event.preventDefault();
    }
    event.returnValue = false;
    return false;
}

// disable scolling on the whole window:
if (!window.addEventListener) {
    // old IE only
    window.attachEvent("onscroll", noScroll);
} else {
    // Firefox only
    window.addEventListener("DOMMouseScroll", noScroll);
    // anything else
    window.addEventListener("scroll", noScroll);
}

// disable scrolling on a single element:
var el = document.getElementById("elementID");

if (!el.addEventListener) {
    el.attachEvent("onscroll", noScroll);
} else {
    el.addEventListener("DOMMouseScroll", noScroll);
    el.addEventListener("scroll", noScroll);
}

这应该够了吧。

09-29 22:57