Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX for #88: Address decay issues, passing animation back to 'pointer…
Browse files Browse the repository at this point in the history
…OffTarget' when mouse moves back away from target.
patricknelson committed May 12, 2016
1 parent 36f695c commit b145cd8
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions js/jquery.parallax.js
Original file line number Diff line number Diff line change
@@ -374,8 +374,9 @@
if (targetPointer[0] === prevPointer[0] && targetPointer[1] === prevPointer[1]) {
return;
}

return updateFn(targetPointer);

// Pass the responsibility for updating back to "pointerOffTarget" now that we're off the target again.
portElem.trigger('parallax.setPointerFn', [pointerOffTarget]);
}

function unport(elem, events, winEvents) {
@@ -441,12 +442,18 @@
timer.add(frame);
timer.start();
},

'mouseleave.parallax': function mouseleave(e) {
// Make the layer come to rest at it's limit with inertia
pointerFn = pointerOffTarget;
// Stop the timer when the the pointer hits target
targetFn = targetOutside;
}
},

// TODO: Needed to set this up as an event listener due to scope issues.
'parallax.setPointerFn': function setPointerFn(e, newPointerFn) {
pointerFn = newPointerFn;
}
};

function updateCss(newPointer) {
@@ -456,7 +463,10 @@
}

function frame() {
pointerFn(port.pointer, pointer, port.threshold, decay, parallax, targetFn, updateCss);
// TODO: Might make sense to eventually refactor calls to pointerFN to simply pass the port instance.
// TODO: Also to have the entire initialization to be based on a jQuery set of just the port [port] and
// TODO: pass the layers as an option instead of the other way around, i.e. [layer, layer, ...]
pointerFn(port.pointer, pointer, port.threshold, decay, parallax, targetFn, updateCss, elem);
}

function targetInside() {

0 comments on commit b145cd8

Please sign in to comment.