本文介绍了单击但不滚动时的指针事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to allow click but not scroll events?

pointer-events: none;

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

Will disable both types of inputs, I would like to disable only scroll. Any other ideas for workarounds?

推荐答案

使用javascript:

Do it with 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);
}

应该可以解决问题.

这篇关于单击但不滚动时的指针事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-26 14:44