Skip to main content
Jarallax provides event callbacks that are triggered at different stages of the parallax lifecycle. These callbacks can be passed as options during initialization.

Event Callbacks

onScroll

Called continuously while the parallax is working, providing detailed scroll calculations.
JarallaxOnScrollCalculations
An object containing scroll position calculations and viewport metrics.

JarallaxOnScrollCalculations Interface

The calculations parameter provides the following properties:
object
The parallax section’s bounding client rectangle containing top, left, width, height, right, and bottom properties.
number
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.
number
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.
number
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.
number
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.
number
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.
number
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.
number
Percentage of the element that is visible in the viewport, ranging from 0 to 1.
  • 0: Element is completely out of view
  • 0.5: Element is 50% visible
  • 1: Element is fully visible in the viewport
Useful for: Triggering animations based on visibility, calculating opacity, or implementing scroll-based progress indicators.
number
Position of the element relative to the center of the viewport, ranging from -1 to 1.
  • -1: Element is at the bottom of the viewport
  • 0: Element center is aligned with viewport center
  • 1: Element is at the top of the viewport
Useful for: Center-based parallax effects or symmetrical animations.

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.
This event fires after:
  • 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.
This event fires after:
  • 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.
This event fires:
  • During initialization after the image is first sized
  • Every time the image is resized (e.g., on window resize)
  • When onResize method 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:
  1. onInit - Fires once after setup is complete
  2. onCoverImage - Fires after initial image sizing
  3. onScroll - Fires for initial scroll position
During normal operation:
  • onScroll - Fires on every scroll event (when element is in/near viewport)
  • onCoverImage - Fires on window resize
During destruction:
  • onDestroy - Fires once when instance is destroyed

Context (this)

Inside all event callbacks, this refers to the Jarallax instance. You have access to:
  • this.$item - The main parallax element
  • this.image - Image-related properties and elements
  • this.image.$container - The parallax container element
  • this.image.$item - The parallax image element
  • this.options - The configuration options
  • this.parallaxScrollDistance - Calculated scroll distance for the parallax effect
If you need to access the original element context, store a reference before initialization.