Skip to content

Instantly share code, notes, and snippets.

@brandoncc
Last active August 29, 2015 13:59
Show Gist options
  • Save brandoncc/10924661 to your computer and use it in GitHub Desktop.
Save brandoncc/10924661 to your computer and use it in GitHub Desktop.
// Fix sliders for mobile devices
YAHOO.util.Event.onDOMReady(function(){
slider_handles = YAHOO.util.Dom.getElementsByClassName('minthumb');
for(i=0; i<slider_handles.length; i++) {
slider_handles[i].addEventListener("touchstart", touchHandler, true);
slider_handles[i].addEventListener("touchmove", touchHandler, true);
slider_handles[i].addEventListener("touchend", touchHandler, true);
slider_handles[i].addEventListener("touchcancel", touchHandler, true);
}
slider_handles = YAHOO.util.Dom.getElementsByClassName('maxthumb');
for(i=0; i<slider_handles.length; i++) {
slider_handles[i].addEventListener("touchstart", touchHandler, true);
slider_handles[i].addEventListener("touchmove", touchHandler, true);
slider_handles[i].addEventListener("touchend", touchHandler, true);
slider_handles[i].addEventListener("touchcancel", touchHandler, true);
}
});
function touchHandler(event) {
var touch = event.changedTouches[0];
var simulatedEvent = document.createEvent("MouseEvent");
simulatedEvent.initMouseEvent({
touchstart: "mousedown",
touchmove: "mousemove",
touchend: "mouseup"
}[event.type], true, true, window, 1,
touch.screenX, touch.screenY,
touch.clientX, touch.clientY, false,
false, false, false, 0, null);
touch.target.dispatchEvent(simulatedEvent);
event.preventDefault();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment