Skip to content

Commit

Permalink
Fix some animation bugs (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
artpolikarpov committed Dec 29, 2013
1 parent 679154e commit 3a0b293
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
10 changes: 8 additions & 2 deletions src/js/animate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
function slide ($el, options) {
var elPos = Math.round(options.pos),
onEndFn = options.onEnd || noop;
var elData = $el.data(),
elPos = Math.round(options.pos),
onEndFn = function () {
elData.sliding = false;
(options.onEnd || noop)();
};

if (typeof options.overPos !== 'undefined' && options.overPos !== options.pos) {
elPos = options.overPos;
Expand All @@ -13,6 +17,8 @@ function slide ($el, options) {
var translate = $.extend(getTranslate(elPos, options._001), options.width && {width: options.width});
console.timeEnd('var translate = $.extend');

elData.sliding = true;

if (CSS3) {
$el.css($.extend(getDuration(options.time), translate));
if (options.time > 10) {
Expand Down
6 changes: 3 additions & 3 deletions src/js/fotorama.js
Original file line number Diff line number Diff line change
Expand Up @@ -1344,9 +1344,9 @@ jQuery.Fotorama = function ($fotorama, opts) {
}
//console.timeEnd('stageShaftTouchTail.onEnd');
},
getPos: function () {
return -getPosByIndex(dirtyIndex, measures.w, opts.margin, repositionIndex);
},
// getPos: function () {
// return -getPosByIndex(dirtyIndex, measures.w, opts.margin, repositionIndex);
// },
_001: true,
timeLow: 1,
timeHigh: 1,
Expand Down
25 changes: 15 additions & 10 deletions src/js/moveontouch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function moveOnTouch ($el, options) {
var el = $el[0],
elData = $el.data(),
tail = {},
startCoo,
coo,
Expand All @@ -14,20 +15,20 @@ function moveOnTouch ($el, options) {
snap,
slowFLAG,
controlFLAG,
moved;
moved,
tracked;

function startTracking (e) {
tracked = true;
startCoo = coo = e._x;
startTime = $.now();
startTime = e._now;

moveTrack = [
[startTime, startCoo]
];

startElPos = moveElPos = tail.noMove ? 0 : stop($el, (options.getPos || noop)(), options._001);

// startTime - endTime < TOUCH_TIMEOUT * 3 && e.preventDefault(); // double tap

(options.onStart || noop).call(el, e);
}

Expand All @@ -37,25 +38,25 @@ function moveOnTouch ($el, options) {
snap = tail.snap;

slowFLAG = e.altKey;
moved = false;
tracked = moved = false;

controlFLAG = result.control;

if (!controlFLAG) {
if (!controlFLAG && !elData.sliding) {
startTracking(e);
}
}

function onMove (e, result) {
if (controlFLAG) {
if (!tracked) {
controlFLAG = false;
startTracking(e);
}

if (!tail.noSwipe) {
coo = e._x;

moveTrack.push([$.now(), coo]);
moveTrack.push([e._now, coo]);

moveElPos = startElPos - (startCoo - coo);

Expand Down Expand Up @@ -84,9 +85,13 @@ function moveOnTouch ($el, options) {
//console.time('moveontouch.js onEnd');
if (controlFLAG) return;

if (!tracked) {
startTracking(result.startEvent);
}

result.touch || MS_POINTER || $el.removeClass(grabbingClass);

endTime = new Date().getTime();
endTime = $.now();

var _backTimeIdeal = endTime - TOUCH_TIMEOUT,
_backTime,
Expand Down Expand Up @@ -149,7 +154,7 @@ function moveOnTouch ($el, options) {

time *= slowFLAG ? 10 : 1;

(options.onEnd || noop).call(el, $.extend(result, {pos: moveElPos, newPos: newPos, overPos: overPos, time: time}));
(options.onEnd || noop).call(el, $.extend(result, {moved: result.moved || longTouchFLAG && snap, pos: moveElPos, newPos: newPos, overPos: overPos, time: time}));
}

tail = $.extend(touch(options.$wrap, {
Expand Down
1 change: 1 addition & 0 deletions src/js/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function extendEvent (e) {
var touch = (e.touches || [])[0] || e;
e._x = touch.pageX;
e._y = touch.clientY;
e._now = $.now();
}

function touch ($el, options) {
Expand Down

0 comments on commit 3a0b293

Please sign in to comment.