diff --git a/js/jquery.parallax.js b/js/jquery.parallax.js index fa15d8f..1f8484c 100644 --- a/js/jquery.parallax.js +++ b/js/jquery.parallax.js @@ -482,7 +482,26 @@ 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 + ); + + // 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; }