Installation
The video extension requires the separatejarallax-video.js file:
Initialization
jarallaxVideo()
Initializes the video extension functionality. Must be called before using video options.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
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
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
CSS class attribute applied to the video element.The video type is automatically appended, creating classes like:
jarallax-video jarallax-video-youtubejarallax-video jarallax-video-vimeojarallax-video jarallax-video-local
videoStartTime
Start time in seconds when the video begins playing.This value is applied on initial play and after each loop iteration.
videoEndTime
End time in seconds when the video stops playing.When set to
0 (default), the video plays until the natural end.videoVolume
Video volume level from
0 to 100.Default is 0 (muted) since most browsers require user interaction for audio playback.videoLoop
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
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
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
Disable video loading on specific user agents or conditions.Can be:
boolean:trueto completely disable videoRegExp: Regular expression to test againstnavigator.userAgentfunction: Custom function that returnstrueto disable video
Video Events
onVideoInsert
Called immediately after the video element is inserted into the parallax container.this.$video.
onVideoWorkerInit
Called after the VideoWorker script is initialized, before the video is inserted.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.