Skip to content

Commit b145cd8

Browse files
committed
FIX for #88: Address decay issues, passing animation back to 'pointerOffTarget' when mouse moves back away from target.
1 parent 36f695c commit b145cd8

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

js/jquery.parallax.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,9 @@
374374
if (targetPointer[0] === prevPointer[0] && targetPointer[1] === prevPointer[1]) {
375375
return;
376376
}
377-
378-
return updateFn(targetPointer);
377+
378+
// Pass the responsibility for updating back to "pointerOffTarget" now that we're off the target again.
379+
portElem.trigger('parallax.setPointerFn', [pointerOffTarget]);
379380
}
380381

381382
function unport(elem, events, winEvents) {
@@ -441,12 +442,18 @@
441442
timer.add(frame);
442443
timer.start();
443444
},
445+
444446
'mouseleave.parallax': function mouseleave(e) {
445447
// Make the layer come to rest at it's limit with inertia
446448
pointerFn = pointerOffTarget;
447449
// Stop the timer when the the pointer hits target
448450
targetFn = targetOutside;
449-
}
451+
},
452+
453+
// TODO: Needed to set this up as an event listener due to scope issues.
454+
'parallax.setPointerFn': function setPointerFn(e, newPointerFn) {
455+
pointerFn = newPointerFn;
456+
}
450457
};
451458

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

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

462472
function targetInside() {

0 commit comments

Comments
 (0)