rangeslider.js mousedown事件不适用于滑块按钮

时间:2017-09-06 16:16:38

标签: javascript jquery rangeslider

鼠标事件未触发。 需要知道hold事件,因此可以禁用滑块值的更新。 我的代码是,

var sliding = false;
function update_seek_value(value){
  if(!sliding){
            $("#replay-slider").val(value).change();
  }
}
$('.slider_button_class_name').on('mousedown',function(){
   sliding = true;
});

2 个答案:

答案 0 :(得分:0)

$("#range-control").rangeslider({
    polyfill: false,
    onSlideEnd: function(position, value){
        //console.log('Position', position, 'Value', value);
        $("#selectedRange").text(value);
    }
});
body, input[type=text] { text-align: center; }
<link href="https://cdnjs.cloudflare.com/ajax/libs/rangeslider.js/1.2.1/rangeslider.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rangeslider.js/1.2.1/rangeslider.min.js"></script>
<input id="range-control" type="range" min="0" max="100" step="1" value="0">
<span id="selectedRange"></span>  

希望这有帮助!

答案 1 :(得分:0)

感谢您对此的帮助,无论如何我自己找到了解决方案。希望这可以帮助那些遇到类似问题的人。 解决方案是覆盖js&#39; rangeslider.min.js&#39;

据我所知,可以禁用“事件”。通过使用$(&#39;选择器&#39;)。off(&#34; mousedown&#34;)或停止事件传播。 我正在使用&#39; /yourlocalpath/rangeslider.js'在rangeslider.js.org中提到 有一个javascript事件正在停止mousedown和touchstart等事件的propogation事件,但基本上它正在监听mousdown事件,所以我在停止事件popogation的代码上方更新了我的标志。 rangelider.js中的代码,我添加了我的标志。

j.prototype.handleDown = function(a) {
console.log("mousedown event triggered"); // TRY TO FIND THIS LINE IN YOUR DOWNLOADED JS OF RANGESLIDER
sliding = true;                           // ADD YOUR MOUSEDOWN EVENTS HERE
if (a.preventDefault(), this.$document.on(this.moveEvent, this.handleMove), this.$document.on(this.endEvent, this.handleEnd), !((" " + a.target.className + " ").replace(/[\n\t]/g, " ").indexOf(this.options.handleClass) > -1)) {
  var b = this.getRelativePosition(a),
    c = this.$range[0].getBoundingClientRect()[this.DIRECTION],
    d = this.getPositionFromNode(this.$handle[0]) - c,
    e = "vertical" === this.orientation ? this.maxHandlePos - (b - this.grabPos) : b - this.grabPos;
  this.setPosition(e), b >= d && b < d + this.handleDimension && (this.grabPos = b - d)
}
}