Swipe left / right without using jquerymobile for android

I am trying to use swipe event to move between pages, here is my code

$( document ).on( "swipeleft", page, function() { 
   $.mobile.changePage( "#"+next, { transition: "slide" },false ); 
}); // Navigate to next page when the "next" button is clicked 
$( ".control .next", page ).on( "click", function() { 
   $.mobile.changePage( "#"+next, { transition: "slide" },false ); 
});

But the swipe does not work properly on Android devices, any help would be much appreciated

Thanks in advance

+3
source share
2 answers

This will launch a swipe (

function( event ) {
  var data = event.originalEvent.touches ?
      event.originalEvent.touches[ 0 ] : event;
  return {
      time: ( new Date() ).getTime(),
      coords: [ data.pageX, data.pageY ],
      origin: $( event.target )
    };
}

)

And when the napkins stop (

function( event ) {
  var data = event.originalEvent.touches ?
      event.originalEvent.touches[ 0 ] : event;
  return {
      time: ( new Date() ).getTime(),
      coords: [ data.pageX, data.pageY ]
    };
}

)

This method receives start and stop objects and processes the logic and triggers for swipe events.

(

function( start, stop ) {
  if ( stop.time - start.time < $.event.special.swipe.durationThreshold &&
    Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ) > $.event.special.swipe.horizontalDistanceThreshold &&
    Math.abs( start.coords[ 1 ] - stop.coords[ 1 ] ) < $.event.special.swipe.verticalDistanceThreshold ) {

    start.origin.trigger( "swipe" )
      .trigger( start.coords[0] > stop.coords[ 0 ] ? "swipeleft" : "swiperight" );
  }
}

)

HTMl code (

<script>
$(function(){
  // Bind the swipeHandler callback function to the swipe event on div.box
  $( "div.box" ).on( "swipe", swipeHandler );

  // Callback function references the event target and adds the 'swipe' class to it
  function swipeHandler( event ){
    $( event.target ).addClass( "swipe" );
  }
});
</script>

)

+1
source

You can try:

$.mobile.changePage( "#"+next, { transition: "slide" },false ); 
//----------put changehash inside this--------------^^--^^^^

:

$.mobile.changePage( "#"+next, { transition: "slide", changeHash: false });
0
source

All Articles