andreruffert / rangeslider.js

🎚 HTML5 input range slider element jQuery polyfill
https://rangeslider.js.org
MIT License
2.16k stars 399 forks source link

Rangeslider captures mousedown #230

Closed luopio closed 8 years ago

luopio commented 8 years ago

I'm using rangeslider.js in a scenario where I need to fire an event when sliding begins. I figured I'd do this with

$('input[type="range"]')
    .rangeslider({
      polyfill: false,
    })
    .on('mousedown touchstart', rangeSliderStart);

but rangeslider captures the mousedown and won't let it bubble up so rangeSliderStart is never called. If I change polyfill to true and use the native widget on Chrome it works as planned.

andreruffert commented 8 years ago

@luopio this should work in your case:

// Adding the EventListener to the `document`.
// Event delegation helps us to call `rangeSliderStart` only
// if `e.currentTarget` is `.rangeslider`
$(document).on('mousedown touchstart', '.rangeslider', rangeSliderStart);

If you would really touch, mousedown the $('input[type="range"]') element it'll work but it's actually visually hidden :)

luopio commented 8 years ago

Ah I see. Thanks for the quick answer.