Plugin Directory

Changeset 2239809


Ignore:
Timestamp:
02/06/2020 01:36:33 PM (6 years ago)
Author:
markbanf
Message:

added touch and mouse drag support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lightweight-slider/trunk/lightweight-slider.js

    r2239109 r2239809  
    139139  }
    140140
    141   $('.lightweight-slider-next').click(function slideNext() {
     141  $('.lightweight-slider-next').click(function (e) {
     142    e.preventDefault();
     143    slideNext();
     144  });
     145
     146  $('.lightweight-slider-prev').click(function (e) {
     147    e.preventDefault();
     148    slidePrev();
     149  });
     150
     151  function slideNext() {
    142152    if ($('.lightweight-slider').hasClass('disabled')) {
    143153      return false;
     
    149159      return false;
    150160    }
    151   });
    152 
    153   $('.lightweight-slider-prev').click(function slidePrev() {
     161  };
     162
     163  function slidePrev() {
    154164    if ($('.lightweight-slider').hasClass('disabled')) {
    155165      return false;
     
    161171      return false;
    162172    }
    163   });
     173  };
    164174
    165175  $('.lightweight-slider-wrapper .pagination div').click(function slideJump() {
     
    174184  });
    175185
     186  // Add touch drag
     187  var $body = $('.lightweight-slider');
     188  $body.on('touchstart', function (evt) {
     189    var startPos = evt.originalEvent.touches[0].clientX;
     190    $body.on('touchend touchmove', function handler(evt) {
     191      if (evt.type === 'touchend') {
     192        // console.log('clicked')
     193      } else {
     194        if (startPos < evt.originalEvent.touches[0].clientX) {
     195          slidePrev();
     196        } else {
     197          slideNext();
     198        };
     199      }
     200      $body.off('touchend touchmove', handler);
     201    });
     202  });
     203
     204  // Add mouse drag
     205  $body.on('mousedown', function (evt) {
     206    var startPos = evt.pageX;
     207    $body.on('mouseup mousemove', function handler(evt) {
     208      if (evt.type === 'mouseup') {
     209        // console.log('clicked')
     210      } else {
     211        if (startPos < evt.pageX) {
     212          slidePrev();
     213        } else {
     214          slideNext();
     215        };
     216      }
     217      $body.off('mouseup mousemove', handler);
     218    });
     219  });
     220
    176221});
Note: See TracChangeset for help on using the changeset viewer.