I’m trying to determine the direction a user swipes across the screen with a mobile device. I see everyone doing the tradition “start position – distance” or vice versa. Though I’d like to know the intentional direction; ie. the user changes direction part way through. The only proper implementations I’ve found are here & here.
Swipe view is nice, but it’s a bit clunky and cubiq wants you sto use his pages system. The other demo is good too, but form what I can tell it just uses a barrage of if else’s to determine direction. So does anyone know of a creative way this could be done that’s lightweight?
Thanks
You need a variable that holds the value of the pointer’s last position. You need a second variable that hold the direction of the swipe. On mousemove, evaluate the direction from the new position and the old one, change the value in the swipe direction variable and then store the new position.