0
我想要做的是创建一个指令,当放置在一个元素(例如选择下拉)禁用该元素的鼠标滚轮滚动,而是滚动页面。我设法找到了两种方法,但都不完整。指令禁用元素滚动行为和滚动页面
这不允许页面的滚动而重点是在元素上(它禁用所有滚动)
over.directive('disableSelectScroll', function() {
return {
restrict: 'A',
link: function (scope, element, attributes) {
element.on('mousewheel', function (e) {
return false;
})
}
}
});
这适用于Firefox和Chrome,但并没有为IE(11)
over.directive('disableSelectScroll', function() {
return {
restrict: 'A',
link: function (scope, element, attributes) {
['touchstart', 'touchmove', 'touchend', 'keydown', 'wheel', 'mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'].forEach(function (eventName) {
element.unbind(eventName);
});
}
}
});
当元素收到mousewheel事件或以某种方式链接到页面滚动行为时,是否必须重新定义滚动行为?