Jquery touchmove event fire when zoom mobile screen

Jquery touchmove event fire when zoom mobile screen

Hi to all,

I have a web page where i used touchmove event to navigate from one page to another.Now the problem is when i am trying to zoom the mobile screen IOS or Android it fire the touchmove event and page changed.

How i can prevent touchmove mean navigation through touchmove while zoom the mobile screen.

Here is the code for move from one next and previour page 

  1. var currentX;
  2. var currentY;
  3. var lastX = 0;
  4. var lastY = 0;
  5. var lastT;
  6. $(document).bind('touchmove', function(e) {
  7.    
  8.     // If still moving clear last setTimeout
  9.     clearTimeout(lastT);

  10.     currentX = e.originalEvent.touches[0].clientX;
  11.     currentY = e.originalEvent.touches[0].clientY;

  12.     // After stoping or first moving
  13.     if(lastX == 0) {
  14.         lastX = currentX;
  15.     }

  16.     if(lastY == 0) {
  17.         lastY = currentY;
  18.     }
  19.     
  20.     var dirX = currentX - lastX;
  21.     var dirY = currentY - lastY;
  22.     
  23.     
  24.     //$('.collection-name').html("Last X="+dirX+"----------Last Y="+dirY);
  25.     if(Math.abs(parseFloat(dirX)) > Math.abs(parseFloat(dirY)))
  26.     { //$('.collection-name').html("Inside Last X="+Math.abs(dirX)+"----------Last Y="+Math.abs(dirY));
  27.          if(parseFloat(currentX) < parseFloat(lastX)) {
  28.         //  $('.collection-name').html($('.next-product-container a.next-product').attr("href"));
  29.            if($('.next-product-container a.next-product').attr("href").length !=='undefined')
  30.            {
  31.                 window.location.href=$('.next-product-container a.next-product').attr("href");
  32.            }
  33.        } else if(parseFloat(currentX) > parseFloat(lastX)){
  34.            // $('.collection-name').html($('.prev-product-container a.prev-product').attr("href"));
  35.            if($('.prev-product-container a.prev-product').attr("href").length !=='undefined')
  36.            {
  37.                window.location.href=$('.prev-product-container a.prev-product').attr("href");
  38.            }

  39.        }
  40.         
  41.     }
  42.     
  43.    
  44.         
  45.       

  46.     // Save last position
  47.     lastX = currentX;
  48.     lastY = currentY;

  49.     // Check if moving is done
  50.     lastT = setTimeout(function() {
  51.         lastX = 0;
  52.         lastY = 0;
  53.     }, 100);
  54. });

thanks