From a470d69442161e609ef9b29fd5972e17e399e2f4 Mon Sep 17 00:00:00 2001 From: Patrick Nelson Date: Mon, 9 May 2016 20:06:58 -0700 Subject: [PATCH 1/2] FIX for #87: Ensure each layer is initialized properly at correct origin x/y on page load. --- js/jquery.parallax.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/js/jquery.parallax.js b/js/jquery.parallax.js index fa15d8f..ff28b3e 100644 --- a/js/jquery.parallax.js +++ b/js/jquery.parallax.js @@ -482,7 +482,21 @@ port.elem.on(events); port.layers = port.layers? port.layers.add(node): jQuery(node); - + + // Initialize this layer at the defined x/y origins now. Subsequent calls to this "pointerFn" will happen + // via the Timer class in repeated calls to the frame() function as the mouse either enter/leaves the + // viewport (a.k.a. "mouseport"). + pointerFn( + // Pointer relative position (0 to 1), x and y. Usually in the middle (i.e. 0.5, 0.5) + [options.xorigin, options.yorigin], + [0, 0], // Pointer relative position we're trying to animate to (0 to 1), x and y. + port.threshold, + 0, // Decay, which we want to override so we initialize immediately. + parallax, + targetFn, + updateCss + ); + /*function freeze() { freeze = true; } From 2d194bea8d8ed9168535cf273e9894ac12ee7213 Mon Sep 17 00:00:00 2001 From: Patrick Nelson Date: Mon, 9 May 2016 20:29:57 -0700 Subject: [PATCH 2/2] FIX for #87 (part 2): Also initialize if mouse is already hovering over viewport. --- js/jquery.parallax.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/js/jquery.parallax.js b/js/jquery.parallax.js index ff28b3e..1f8484c 100644 --- a/js/jquery.parallax.js +++ b/js/jquery.parallax.js @@ -497,6 +497,11 @@ updateCss ); + // Also if the mouse happens to already be over the viewport, trigger an initial "mouseenter" now (since + // otherwise user would need to move mouse completely out of the viewport and then back in, in order to + // initialize the effect when it should already be started). + if (elem.is(':hover')) elem.mouseenter(); + /*function freeze() { freeze = true; }