Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 禁用jQuery旋钮上的鼠标滚轮_Javascript_Jquery_Mousewheel_Jquery Knob - Fatal编程技术网

Javascript 禁用jQuery旋钮上的鼠标滚轮

Javascript 禁用jQuery旋钮上的鼠标滚轮,javascript,jquery,mousewheel,jquery-knob,Javascript,Jquery,Mousewheel,Jquery Knob,有可能吗 我正在尝试禁用鼠标滚轮,但仍允许其可拖动/可调节。您可以将旋钮设置为readOnly:true,但这不会让您拖动刻度盘。有什么想法吗 $(".dial").knob({ min: 1 max: 10 stopper: true, readOnly: true,//if true This will Set the Knob readonly cannot click release: function (value) { //Do s

有可能吗

我正在尝试禁用鼠标滚轮,但仍允许其可拖动/可调节。您可以将旋钮设置为readOnly:true,但这不会让您拖动刻度盘。有什么想法吗

$(".dial").knob({
    min: 1
    max: 10
    stopper: true,
    readOnly: true,//if true This will Set the Knob readonly cannot click
    release: function (value) {
      //Do something as you release the mouse
    }
});

$(".dial").bind("mousewheel", function() {
   return false;
});

我找到了一个解决方案,虽然不太理想,但效果不错

在knob.js文件中,我注释掉了绑定鼠标滚轮功能的两行(第669行和第670行):

“readonly”属性就可以了


阅读jquery-knob.js的源代码,搜索“滚动”,您将发现以下代码:

this.$c.bind("mousewheel DOMMouseScroll", mw);
this.$.bind("mousewheel DOMMouseScroll", mw);
没有配置来决定是否使用scroll,您可以对该代码进行注释以获得工作,但如果您的lib文件由bower或npm管理,您将遇到问题。。。。。。每次更新lib文件时,都需要再次进行注释。 因此,禁用滚动的另一种方法是:

$(".dial").knob({
    min: 1
    max: 10
    stopper: true,
    readOnly: true,//if true This will Set the Knob readonly cannot click
    release: function (value) {
      //Do something as you release the mouse
    }
}).children().off('mousewheel DOMMouseScroll');

通常,
'.dial'
元素是一个输入元素,您可以调用旋钮方法来初始化旋钮,它返回一个div(jquery元素样式)来包装
'.dial'
元素(
上面源代码中此
的$)和一个新添加的canvas元素(
上面源代码中此
的$c),因此,我们调用
children().off('mouseweel-DOMMouseScroll')
以删除滚动事件侦听器

您是否尝试在您的mouseweel侦听器中使用
event.preventDefault()
?尝试解除绑定“DOMMouseScroll”尝试了这两种方法,但仍然没有成功。
$(".dial").knob({
    min: 1
    max: 10
    stopper: true,
    readOnly: true,//if true This will Set the Knob readonly cannot click
    release: function (value) {
      //Do something as you release the mouse
    }
}).children().off('mousewheel DOMMouseScroll');