Skip to main content
The Jarallax video extension enables video backgrounds with parallax effects. It supports YouTube, Vimeo, and self-hosted video files.

Installation

The video extension requires the separate jarallax-video.js file:

Initialization

jarallaxVideo()

Initializes the video extension functionality. Must be called before using video options.
typeof jarallax
Optional. The jarallax instance to extend. If not provided, uses the global jarallax instance.
The video extension must be initialized before calling jarallax() with video options. Typically, call jarallaxVideo() once at the start of your application.

Video Options

When the video extension is loaded, these additional options become available:

videoSrc

string
default:"null"
URL of the video to use as background. Supports:
  • YouTube: Full URL or watch ID
  • Vimeo: Full URL or video ID
  • Self-hosted: Path with format prefixes
Can also be set via the data-jarallax-video HTML attribute.

YouTube Examples

Vimeo Examples

Self-Hosted Video Examples

Self-hosted videos require format prefixes (mp4:, webm:, ogv:). You only need one format, but providing multiple formats ensures maximum browser compatibility.

videoClass

string
default:"jarallax-video"
CSS class attribute applied to the video element.The video type is automatically appended, creating classes like:
  • jarallax-video jarallax-video-youtube
  • jarallax-video jarallax-video-vimeo
  • jarallax-video jarallax-video-local

videoStartTime

number
default:"0"
Start time in seconds when the video begins playing.This value is applied on initial play and after each loop iteration.

videoEndTime

number
default:"0"
End time in seconds when the video stops playing.When set to 0 (default), the video plays until the natural end.

videoVolume

number
default:"0"
Video volume level from 0 to 100.Default is 0 (muted) since most browsers require user interaction for audio playback.
Many browsers block autoplay videos with sound. It’s recommended to keep videos muted (videoVolume: 0) for background videos to ensure they play automatically.

videoLoop

boolean
default:"true"
Whether to loop the video infinitely.When false, the video plays once and stops. When using videoStartTime, the loop restarts at the specified time.

videoPlayOnlyVisible

boolean
default:"true"
Play video only when the parallax element is visible in the viewport.Automatically pauses the video when scrolled out of view and resumes when visible again. Improves performance and reduces bandwidth usage.

videoLazyLoading

boolean
default:"true"
Preload and insert videos only when the parallax element becomes visible in the viewport.Significantly improves initial page load performance by deferring video loading until needed.
Lazy loading is highly recommended for pages with multiple video backgrounds or when the video is below the fold.

disableVideo

boolean | RegExp | function
default:"false"
Disable video loading on specific user agents or conditions.Can be:
  • boolean: true to completely disable video
  • RegExp: Regular expression to test against navigator.userAgent
  • function: Custom function that returns true to disable video
When disabled, falls back to the image background if available.

Video Events

onVideoInsert

Called immediately after the video element is inserted into the parallax container.
At this point, the video element is available via this.$video.

onVideoWorkerInit

Called after the VideoWorker script is initialized, before the video is inserted.
VideoWorker
The VideoWorker instance that handles video playback. Provides methods like play(), pause(), and events.

Complete Video Example

HTML Data Attribute Example

Video Types

The extension automatically detects the video type:

YouTube

Supports standard YouTube URLs and video IDs. Automatically uses YouTube iframe API.

Vimeo

Supports Vimeo URLs and video IDs. Automatically uses Vimeo Player API.

Self-Hosted

Supports MP4, WebM, and OGV formats. Uses HTML5 video element with native controls disabled.

Performance Tips

Enable lazy loading: Keep videoLazyLoading: true to defer video loading until needed.Use visibility control: Keep videoPlayOnlyVisible: true to pause videos when not in view.Provide fallback images: Always set imgSrc as a fallback for when videos are disabled or fail to load.Disable on mobile: Use disableVideo to show static images on mobile devices to save bandwidth.Optimize video files: For self-hosted videos, compress and optimize file sizes. Consider using a CDN.