Methods
Methods allow you to programmatically control Jarallax instances after initialization.destroy
Completely removes the Jarallax effect and restores the element to its original state.- JavaScript
- jQuery
What destroy does
What destroy does
From the source code, the
destroy method:- Removes the parallax observer
- Restores original styles from
data-jarallax-original-stylesattribute - Moves the image element back to its original position (if using
<img>tag) - Removes the parallax container element from the DOM
- Calls the
onDestroycallback if defined - Deletes the jarallax instance from the element
isVisible
Checks if the parallax element is currently visible in the viewport.- JavaScript
- jQuery
boolean
This method returns
true if the element is currently in the viewport, false otherwise.onResize
Manually triggers the resize handler to recalculate and refit the parallax image.- JavaScript
- jQuery
When to use onResize
When to use onResize
Call From the source code:
onResize when:- The container element size changes dynamically
- Content is loaded that affects layout
- Window is resized programmatically
- Elements are shown/hidden
- Orientation changes on mobile devices
onScroll
Manually triggers the scroll handler to recalculate the parallax image position.- JavaScript
- jQuery
Jarallax automatically calls this method on window scroll. You only need to call it manually if you’re programmatically scrolling or need to force a position update.
Method Examples
Conditional Destroy
Dynamic Content Loading
Visibility-Based Actions
Events
Events allow you to hook into different stages of the parallax lifecycle.onInit
Called after Jarallax initialization completes.Context and available properties
Context and available properties
Inside event callbacks,
this refers to the Jarallax instance with access to:this.$item- The parallax container elementthis.options- Current configuration optionsthis.image- Image data objectthis.image.$container- The parallax image containerthis.image.$item- The image elementthis.$video- Video element (if using video extension)
onDestroy
Called after the Jarallax instance is destroyed.onCoverImage
Called after the parallax image is covered/fitted to the container.This event is triggered during initialization and whenever the container is resized.
onScroll
Called continuously during scrolling with detailed calculation data.onScroll Event Calculations
TheonScroll event provides detailed information about the parallax element’s position and visibility.
Calculation Object
Calculation Properties Explained
visiblePercent
visiblePercent
Represents how much of the element is visible in the viewport.
1.0: Fully visible0.5: Half visible0.0: Not visible
fromViewportCenter
fromViewportCenter
Position relative to the viewport center, ranging from
-1 to 1.-1: Top of element is at viewport center0: Center of element is at viewport center1: Bottom of element is at viewport center
section (rect)
section (rect)
The element’s
DOMRect object containing position and dimensions:Practical onScroll Examples
- Progress Indicator
- Trigger Animation
- Custom Parallax Math
- Visibility Logging
Video Extension Events
When using the video extension, additional events are available.onVideoInsert
Called when the video element is inserted into the DOM.Access the video element via
this.$video in the callback.onVideoWorkerInit
Called when the VideoWorker instance is initialized.VideoWorker events
VideoWorker events
The VideoWorker instance provides these events:
ready- Video is loaded and ready to playstarted- Video has started playingplay- Video play eventpause- Video pause eventended- Video has endederror- Video loading or playback error
onVideoWorkerInit.Complete API Example
Here’s a comprehensive example using methods and events:TypeScript Support
Jarallax includes TypeScript definitions. Here’s how to use them:Best Practices
1
Use events for initialization tasks
Perform setup work in
onInit to ensure Jarallax is fully ready:2
Clean up in onDestroy
Remove event listeners and custom elements in
onDestroy:3
Throttle onScroll callbacks
Limit heavy operations in
onScroll to maintain performance:Next Steps
Basic Usage
Learn the fundamentals of Jarallax
Advanced Options
Explore advanced configuration options
