Main Function
jarallax()
The main function used to initialize Jarallax or call methods on existing instances.Parameters
The DOM element(s) to initialize or call methods on.Can be:
- A single DOM element
- An array of elements
- A NodeList (e.g., from
querySelectorAll) - A jQuery object (UMD mode only)
Either:
- A configuration object for initialization (see Options)
- A method name string to call on existing instances
Initialization Example
jQuery Usage (UMD mode)
Instance Methods
Once initialized, you can call methods on Jarallax instances by passing the method name as the second parameter.destroy
Destroys the Jarallax instance and restores the element to its original state before initialization.- Removes all Jarallax-created DOM elements (container, parallax image)
- Restores original element styles from before initialization
- Removes parallax observers and event listeners
- Restores the original
<img>tag to its original position (if applicable) - Calls the
onDestroycallback if provided - Deletes the jarallax instance from the element
isVisible
Checks if the parallax element is currently visible in the viewport.boolean - true if the element is in the viewport, false otherwise.
This method returns the visibility status based on the first element in the collection.
onResize
Recalculates and updates the parallax image size and container clipping. This method is automatically called on window resize and load events.- After changing element dimensions via JavaScript
- After showing/hiding the element
- After layout changes that affect the element’s size
- After modifying CSS that affects dimensions
onScroll
Recalculates and updates the parallax image position based on the current scroll position. This method is automatically called on window scroll events.- After programmatic scrolling
- In custom scroll containers
- When implementing custom scroll logic
- To force an immediate position update
Complete Usage Example
Method Chaining
Most methods return
void, so method chaining is not supported. The exception is isVisible, which returns a boolean value.