Skip to main content
Jarallax provides several methods to control parallax instances after initialization. Methods can be called on elements that have already been initialized with Jarallax.

Main Function

jarallax()

The main function used to initialize Jarallax or call methods on existing instances.

Parameters

Element | Element[] | NodeListOf<Element> | JQuery<Element>
required
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)
JarallaxOptions | string
required
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.
What it does:
  • 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 onDestroy callback if provided
  • Deletes the jarallax instance from the element

isVisible

Checks if the parallax element is currently visible in the viewport.
Returns: 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.
When to use manually:
  • 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.
When to use manually:
  • 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.

jQuery No-Conflict Mode

If you’re using jQuery and need to avoid namespace collisions: