Changeset 2239809
- Timestamp:
- 02/06/2020 01:36:33 PM (6 years ago)
- File:
-
- 1 edited
-
lightweight-slider/trunk/lightweight-slider.js (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lightweight-slider/trunk/lightweight-slider.js
r2239109 r2239809 139 139 } 140 140 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() { 142 152 if ($('.lightweight-slider').hasClass('disabled')) { 143 153 return false; … … 149 159 return false; 150 160 } 151 } );152 153 $('.lightweight-slider-prev').click(function slidePrev() {161 }; 162 163 function slidePrev() { 154 164 if ($('.lightweight-slider').hasClass('disabled')) { 155 165 return false; … … 161 171 return false; 162 172 } 163 } );173 }; 164 174 165 175 $('.lightweight-slider-wrapper .pagination div').click(function slideJump() { … … 174 184 }); 175 185 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 176 221 });
Note: See TracChangeset
for help on using the changeset viewer.