Answer the question
In order to leave comments, you need to log in
How to swipe in JS?
How to make a swipe in pure JS? I need that when I press, hold and move the left mouse button / finger, the picture in the slider follows the cursor / finger. And when the cursor/finger was released, the slide moved if the swipe was more than a quarter or a third of the parent element. In short, it works just like in the slick slider:
https://kenwheeler.github.io/slick/
Answer the question
In order to leave comments, you need to log in
As soon as the mouseover event is fired, you count milliseconds until mouseout.
If mouseout didn't happen within about 250ms, then you understand that it was a slide. And then everything is simple.
You calculate how much the cursor moved to the left or right and move your picture by that much. The speed with which to move can also be according to the formula from the school curriculum.
With the latter, everything is also simple, if mouseout occurs when the mouse has traveled a path equal to 1/4 or 1/3 of the width of the parent element, you simply scroll the image.
No, there is no single API for this. There is a Touch API and a MouseEvent API . I would advise you not to invent the bicycle when the motorcycle was invented.
In short, just like in the slick slider, it worksWhat's stopping you from looking at the source code of the slick slider?
To make the swipe the way you want, you have to write a lot of code. Hardly anyone would want to do it.
If you want to learn how to do these things, then public libraries have github repositories where you can see the implementation of certain features. Go and see how the swipe methods are described there. Here will be the answer.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question