javascript - 如何在没有 'update' 触发的情况下设置 slider 值?

标签 javascript jquery nouislider

我希望能够在不触发更新事件的情况下设置 slider 值。我尝试在 set 函数中设置第二个参数 (fireSetEvent),但这不起作用。

nouiContrast = document.getElementById('nouiContrast');
noUiSlider.create(nouiContrast, {
  start: 0,
  step: 0.01,
  behaviour: 'tap',
  connect: [true, false],
  range: {
    'min': 0,
    'max': 1
  }
});
nouiContrast.noUiSlider.on('update', function(values, handle) {
  applyFilterValue(6, 'contrast', values[handle]);
});

//....

nouiContrast.noUiSlider.set(val, false);

最佳答案

如果你只想在用户拖动 slider 时处理更新而不是在代码设置更新时处理,你可以听slide事件。

来自文档:

This event is useful when you specifically want to listen to a handle being dragged, but want to ignore other updates to the slider value. This event also fires on a change by a 'tap'. In most cases, the update is the better choice.

nouiContrast = document.getElementById('nouiContrast');
noUiSlider.create(nouiContrast, {
  start: 0,
  step: 0.01,
  behaviour: 'tap',
  connect: [true, false],
  range: {
    'min': 0,
    'max': 1
  }
});
nouiContrast.noUiSlider.on('slide', function(values, handle) {
  applyFilterValue(6, 'contrast', values[handle]);
});

//....

nouiContrast.noUiSlider.set(val, false);

关于javascript - 如何在没有 'update' 触发的情况下设置 slider 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47652050/

相关文章:

javascript - $.noUiSlider 垂直 slider ,最大值在顶部,最小值在底部

javascript - Bx Slider 增加div的高度

javascript - 如何打印弹出窗口内容

javascript - 如何从jquery对象获取html元素

javascript - 想要将 h1 更改为用户在单击提交按钮后在输入框中输入的文本

javascript - noUiSlider 多范围访问第一个句柄

javascript - 使用第三方库和 React js 出现错误

javascript - 填充后 MongooseJS 返回空数组

javascript - HTML 元素的坐标

javascript - 如何将我的 Ionic 应用程序与我的 java 服务器(Spring MVC)连接?