Browse Source

fixing issue when after slide a touch event on the slider triggers the slider to move

pull/197/head
Ilya Scharrenbroich 12 years ago
parent
commit
bfa8ff8a09
  1. 5
      dist/ratchet.js
  2. 5
      lib/js/sliders.js

5
dist/ratchet.js vendored

@ -577,6 +577,7 @@
var slideNumber; var slideNumber;
var isScrolling; var isScrolling;
var scrollableArea; var scrollableArea;
var hasMoved;
var getSlider = function (target) { var getSlider = function (target) {
var i, sliders = document.querySelectorAll('.slider ul'); var i, sliders = document.querySelectorAll('.slider ul');
@ -626,6 +627,7 @@
deltaY = e.touches[0].pageY - pageY; deltaY = e.touches[0].pageY - pageY;
pageX = e.touches[0].pageX; pageX = e.touches[0].pageX;
pageY = e.touches[0].pageY; pageY = e.touches[0].pageY;
hasMoved = true;
if (typeof isScrolling == 'undefined') { if (typeof isScrolling == 'undefined') {
isScrolling = Math.abs(deltaY) > Math.abs(deltaX); isScrolling = Math.abs(deltaY) > Math.abs(deltaX);
@ -644,7 +646,7 @@
}; };
var onTouchEnd = function (e) { var onTouchEnd = function (e) {
if (!slider || isScrolling) return; if (!slider || isScrolling || !hasMoved) return;
setSlideNumber( setSlideNumber(
(+new Date) - startTime < 1000 && Math.abs(deltaX) > 15 ? (deltaX < 0 ? -1 : 1) : 0 (+new Date) - startTime < 1000 && Math.abs(deltaX) > 15 ? (deltaX < 0 ? -1 : 1) : 0
@ -662,6 +664,7 @@
}); });
slider.parentNode.dispatchEvent(e); slider.parentNode.dispatchEvent(e);
hasMoved = false
}; };
window.addEventListener('touchstart', onTouchStart); window.addEventListener('touchstart', onTouchStart);

5
lib/js/sliders.js

@ -20,6 +20,7 @@
var slideNumber; var slideNumber;
var isScrolling; var isScrolling;
var scrollableArea; var scrollableArea;
var hasMoved;
var getSlider = function (target) { var getSlider = function (target) {
var i, sliders = document.querySelectorAll('.slider ul'); var i, sliders = document.querySelectorAll('.slider ul');
@ -69,6 +70,7 @@
deltaY = e.touches[0].pageY - pageY; deltaY = e.touches[0].pageY - pageY;
pageX = e.touches[0].pageX; pageX = e.touches[0].pageX;
pageY = e.touches[0].pageY; pageY = e.touches[0].pageY;
hasMoved = true;
if (typeof isScrolling == 'undefined') { if (typeof isScrolling == 'undefined') {
isScrolling = Math.abs(deltaY) > Math.abs(deltaX); isScrolling = Math.abs(deltaY) > Math.abs(deltaX);
@ -87,7 +89,7 @@
}; };
var onTouchEnd = function (e) { var onTouchEnd = function (e) {
if (!slider || isScrolling) return; if (!slider || isScrolling || !hasMoved) return;
setSlideNumber( setSlideNumber(
(+new Date) - startTime < 1000 && Math.abs(deltaX) > 15 ? (deltaX < 0 ? -1 : 1) : 0 (+new Date) - startTime < 1000 && Math.abs(deltaX) > 15 ? (deltaX < 0 ? -1 : 1) : 0
@ -105,6 +107,7 @@
}); });
slider.parentNode.dispatchEvent(e); slider.parentNode.dispatchEvent(e);
hasMoved = false
}; };
window.addEventListener('touchstart', onTouchStart); window.addEventListener('touchstart', onTouchStart);

Loading…
Cancel
Save