Advertisement
tommyosheawebdesign

Enable mobile scroll on rev slider

Jul 3rd, 2019
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function() {
  2.  
  3. if(!('ontouchend' in document)) return;
  4. var pageX, pageY, newX, newY, linked;
  5.  
  6. jQuery('.rev_slider').on('touchstart', function(event) {
  7.  
  8.     newX = newY = false;
  9.  
  10.     var target = jQuery(event.target),
  11.     clas = target.attr('class');
  12.     event = event.originalEvent;
  13.  
  14.     if(event.touches) event = event.touches[0];
  15.     pageX = event.pageX;
  16.     pageY = event.pageY;
  17.  
  18.     if(target.is('a') || target.closest('a').length) linked = target;
  19.  
  20. }).on('touchmove', function(event) {
  21.  
  22.     event = event.originalEvent;
  23.     if(event.touches) event = event.touches[0];
  24.  
  25.     newX = event.pageX;
  26.     newY = event.pageY;
  27.     if(Math.abs(pageX - newX) > 10) event.preventDefault();
  28.  
  29. }).on('touchend', function(event) {
  30.  
  31.     if(newX !== false && Math.abs(pageX - newX) > 30) {
  32.  
  33.         eval('revapi' + jQuery(this).closest('.rev_slider_wrapper').attr('id').split('rev_slider_')[1].split('_')[0])[pageX > newX ? 'revnext' : 'revprev']();
  34.  
  35.     }
  36.     else if((linked && newY === false) || (linked && Math.abs(pageY - newY) < 10)) {
  37.  
  38.         linked = linked.is('a') ? linked : linked.closest('a');
  39.         if(linked.length) {
  40.  
  41.             if(linked.attr('target') === '_blank') {    
  42.                 window.open(linked.attr('href'));
  43.             }
  44.             else {
  45.                 window.location = linked.attr('href');
  46.             }
  47.  
  48.         }
  49.  
  50.     }
  51.  
  52.     linked = newX = false;
  53.  
  54. });})();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement