javascript - Slider for touchscreens -
i have here such slider:https://jsfiddle.net/args91l4/ how work on touch screens, more precisely ways without third-party plugins on vanilla js or pure jquery? thought track mouse events like:
.mousedown(); //start moving .mousemove (); //track coordinates .mouseup(); //end moving
how implement it? or there ways easier?
you're not looking mouse events, touch events, e.g. touchstart
it's not easy, though, need decide after every touch user wanted achieve. if scrolls down left, did want slide left or did want scroll down , wasn't precise? or did want click , mistakenly moved little bit right? requires quite lot of calculations , assumptions , may quite hard.
therefore i'd recommend use lib hammerjs this, simplifies configuration , comes pretty solid defaults. in hammerjs use swipe recognizer detecting user wanting slide left or right this
var hammerinstance = new hammer(element, options); hammerinstance.on('swipeleft', function(ev) { ... // slide left }
Comments
Post a Comment