Event Callbacks
onScroll
Called continuously while the parallax is working, providing detailed scroll calculations.An object containing scroll position calculations and viewport metrics.
JarallaxOnScrollCalculations Interface
Thecalculations parameter provides the following properties:
The parallax section’s bounding client rectangle containing
top, left, width, height, right, and bottom properties.Distance in pixels before the element reaches the top of the viewport.
0 when the element top is at or past the viewport top.Useful for: Detecting when element is about to enter from bottom.Distance in pixels before the element completely passes the top of the viewport.
0 when element has completely scrolled past the top.Useful for: Detecting when element is fully visible or has passed the top.Distance in pixels after the element top has passed the viewport top.
0 when element hasn’t reached the top yet.Useful for: Measuring how far the element has scrolled into view from the top.Distance in pixels before the element top reaches the bottom of the viewport.
0 when element top is at or past the viewport bottom.Useful for: Detecting when element is entering from the bottom.Distance in pixels before the element bottom passes the viewport bottom.
0 when element has completely exited from the bottom.Useful for: Detecting when element is about to completely leave viewport.Distance in pixels after the element bottom has passed above the viewport bottom.
0 when element is still visible.Useful for: Measuring how far the element has scrolled out of view.Percentage of the element that is visible in the viewport, ranging from
0 to 1.0: Element is completely out of view0.5: Element is 50% visible1: Element is fully visible in the viewport
Position of the element relative to the center of the viewport, ranging from
-1 to 1.-1: Element is at the bottom of the viewport0: Element center is aligned with viewport center1: Element is at the top of the viewport
Usage Example
Calculations Visualization
The
onScroll callback is performance-optimized and only fires when the element is in or near the viewport. It does not fire continuously when the element is completely out of view.onInit
Called once after Jarallax initialization is complete.- The parallax container is created
- The image is positioned
- Initial size and scroll calculations are complete
- The element is ready for parallax effects
Usage Example
Inside the callback,
this refers to the Jarallax instance, giving you access to instance properties like this.$item, this.image, and this.options.onDestroy
Called after the Jarallax instance has been destroyed.- The parallax container is removed
- Original element styles are restored
- Event listeners and observers are cleaned up
- The instance is deleted from the element
Usage Example
onCoverImage
Called after the parallax image is sized and positioned to cover the container.- During initialization after the image is first sized
- Every time the image is resized (e.g., on window resize)
- When
onResizemethod is called
Usage Example
This callback is useful for debugging image sizing issues or implementing custom image positioning logic.
Complete Example
Here’s a complete example using all event callbacks:Event Execution Order
During initialization:- onInit - Fires once after setup is complete
- onCoverImage - Fires after initial image sizing
- onScroll - Fires for initial scroll position
- onScroll - Fires on every scroll event (when element is in/near viewport)
- onCoverImage - Fires on window resize
- onDestroy - Fires once when instance is destroyed
