Вопрос

I am using Zepto (with the Touch Module)
I have a div with a 'swipe' listener on it.
I want the div to follow the finger of the user when swiping it, just as you swipe away your notifications on your Android or iPhone. Is there a way of getting the swipe/finger position on the swipe event? so I can put the div to position: relative with a left: [finger left position]

Это было полезно?

Решение

I found a solution for it, you have to bind it to the touchmove event, not the swipe one:

$(".element").on('touchmove', function( e ){
    var x = e.touches[0].pageX;
    $(this).css('left', x);
});

And of course add an ontouchend event in order to replace the element where it was in the beginning (in case the user released the swiped element)

It's also even better to use -webkit-translate: (70px 0px) for faster performance (replace 70px with x)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top