Convert Figma logo to code with AI

nk-o logojarallax

Parallax scrolling for modern browsers

1,389
213
1,389
23

Top Related Projects

10,422

Simple & lightweight (<4kb gzipped) vanilla JavaScript library to create smooth & beautiful animations when you scroll.

The javascript library for magical scroll interactions.

16,455

Parallax Engine that reacts to the orientation of a smart device

7,064

Lightweight, vanilla javascript parallax library

Animate elements as they scroll into view.

Quick Overview

Jarallax is a lightweight JavaScript library for creating parallax scrolling effects on websites. It allows developers to easily add smooth, performant parallax backgrounds to their web pages, supporting various types of content including images and videos.

Pros

  • Easy to use with minimal setup required
  • Supports both image and video parallax effects
  • Highly customizable with numerous options and settings
  • Lightweight and performant, with minimal impact on page load times

Cons

  • May not work perfectly on all mobile devices due to varying scroll behavior
  • Limited built-in animation options beyond basic parallax scrolling
  • Requires JavaScript to function, which may not be ideal for all use cases
  • Documentation could be more comprehensive for advanced usage scenarios

Code Examples

  1. Basic image parallax:
jarallax(document.querySelectorAll('.jarallax'), {
    speed: 0.2
});

This code applies a parallax effect to all elements with the 'jarallax' class, with a scroll speed of 0.2.

  1. Video parallax:
jarallax(document.querySelectorAll('.jarallax-video'), {
    speed: 0.5,
    videoSrc: 'https://youtu.be/mru3Q5m4lkY'
});

This example creates a video parallax effect on elements with the 'jarallax-video' class, using a YouTube video as the source.

  1. Custom scroll speed for specific elements:
jarallax(document.querySelector('#custom-speed'), {
    speed: -0.5,
    imgPosition: '50% 0%'
});

This code applies a reverse parallax effect (negative speed) to a specific element with the ID 'custom-speed', and positions the background image at the top center.

Getting Started

  1. Include the Jarallax script in your HTML:
<script src="https://unpkg.com/jarallax@2/dist/jarallax.min.js"></script>
  1. Add the 'jarallax' class to the elements you want to apply the parallax effect to:
<div class="jarallax">
    <img class="jarallax-img" src="path/to/your/image.jpg" alt="">
</div>
  1. Initialize Jarallax in your JavaScript:
jarallax(document.querySelectorAll('.jarallax'));

This basic setup will apply a default parallax effect to all elements with the 'jarallax' class. You can customize the effect by passing additional options to the jarallax function.

Competitor Comparisons

10,422

Simple & lightweight (<4kb gzipped) vanilla JavaScript library to create smooth & beautiful animations when you scroll.

Pros of lax.js

  • Lightweight and minimal, with a smaller file size
  • Easier to set up and use for simple parallax effects
  • Supports a wider range of animation types beyond just parallax

Cons of lax.js

  • Less customizable for complex parallax scenarios
  • Fewer built-in features compared to Jarallax
  • May require more manual configuration for advanced use cases

Code Comparison

lax.js:

lax.addDriver('scrollY', function () {
  return window.scrollY
})

lax.addElements('.selector', {
  scrollY: {
    translateY: [
      ["elInY", "elOutY"],
      [0, 100],
    ]
  }
})

Jarallax:

jarallax(document.querySelectorAll('.jarallax'), {
  speed: 0.2,
  imgSrc: 'path/to/image.jpg'
});

Both libraries offer ways to create parallax effects, but lax.js provides a more flexible approach for various animation types, while Jarallax focuses specifically on parallax scrolling with images. lax.js requires more manual setup for drivers and elements, whereas Jarallax offers a simpler API for basic parallax functionality. The choice between the two depends on the specific project requirements and the desired level of customization.

The javascript library for magical scroll interactions.

Pros of ScrollMagic

  • More comprehensive animation control, including timeline-based animations
  • Extensive documentation and community support
  • Flexible integration with other animation libraries like GSAP

Cons of ScrollMagic

  • Steeper learning curve due to more complex API
  • Larger file size, which may impact page load times
  • Less focused on parallax effects specifically

Code Comparison

ScrollMagic:

var controller = new ScrollMagic.Controller();
var scene = new ScrollMagic.Scene({
    triggerElement: "#trigger",
    duration: 300
})
.setTween("#animate", {scale: 2.5})
.addTo(controller);

Jarallax:

jarallax(document.querySelectorAll('.jarallax'), {
    speed: 0.2,
    imgSrc: 'path/to/image.jpg'
});

ScrollMagic offers more granular control over animations, allowing for complex scroll-based interactions. It uses a scene-based approach, where you define trigger points and durations for animations. This makes it suitable for a wide range of scroll-based effects beyond just parallax.

Jarallax, on the other hand, is more focused on parallax effects and has a simpler API. It's easier to set up for basic parallax scrolling but may be less flexible for complex animations. Jarallax is lighter and more performant for parallax-specific use cases, while ScrollMagic is better suited for projects requiring diverse scroll-based animations and interactions.

16,455

Parallax Engine that reacts to the orientation of a smart device

Pros of Parallax

  • Lightweight and simple to use, with minimal setup required
  • Supports various input methods (mouse, gyroscope, accelerometer)
  • Offers a wide range of customization options for parallax effects

Cons of Parallax

  • Less actively maintained, with fewer recent updates
  • Limited browser compatibility compared to Jarallax
  • Lacks some advanced features like video backgrounds

Code Comparison

Parallax initialization:

var scene = document.getElementById('scene');
var parallax = new Parallax(scene);

Jarallax initialization:

jarallax(document.querySelectorAll('.jarallax'), {
    speed: 0.2
});

Both libraries offer simple initialization, but Jarallax provides more options for customization directly in the initialization code.

Parallax focuses on creating parallax effects based on mouse movement or device orientation, while Jarallax specializes in scroll-based parallax effects and offers additional features like video backgrounds.

Jarallax has better documentation and more frequent updates, making it potentially easier to integrate and maintain in long-term projects. However, Parallax might be a better choice for simpler projects or those requiring device orientation-based effects.

Consider your specific project requirements, desired features, and long-term maintenance needs when choosing between these two libraries.

7,064

Lightweight, vanilla javascript parallax library

Pros of Rellax

  • Lightweight and simple to use, with minimal setup required
  • Supports vertical and horizontal parallax effects
  • Works well with mobile devices and responsive designs

Cons of Rellax

  • Limited customization options compared to Jarallax
  • Lacks advanced features like video backgrounds or automatic content sizing
  • May require additional code for complex parallax scenarios

Code Comparison

Rellax:

var rellax = new Rellax('.rellax', {
  speed: -2,
  center: false,
  wrapper: null,
  round: true,
  vertical: true,
  horizontal: false
});

Jarallax:

jarallax(document.querySelectorAll('.jarallax'), {
  speed: 0.2,
  imgSize: 'cover',
  imgPosition: '50% 50%',
  disableParallax: /iPad|iPhone|iPod|Android/,
  automaticResize: true
});

Both libraries offer easy-to-use parallax effects, but Jarallax provides more advanced features and customization options. Rellax is simpler and lighter, making it a good choice for basic parallax needs, while Jarallax is better suited for complex, feature-rich parallax implementations. The code examples show that Rellax focuses on speed and direction, while Jarallax offers more control over image handling and device-specific behavior.

Animate elements as they scroll into view.

Pros of ScrollReveal

  • Focused specifically on scroll-based animations, making it more specialized for this purpose
  • Lighter weight and potentially faster for simple scroll reveal effects
  • Easier to set up for basic scroll animations with less configuration required

Cons of ScrollReveal

  • Less versatile compared to Jarallax, which offers parallax effects in addition to scroll animations
  • May require additional libraries or custom code for more complex parallax-style effects
  • Limited to scroll-triggered animations, while Jarallax supports various parallax types

Code Comparison

ScrollReveal:

ScrollReveal().reveal('.element', {
    delay: 200,
    distance: '50px',
    origin: 'bottom'
});

Jarallax:

jarallax(document.querySelectorAll('.jarallax'), {
    speed: 0.2,
    type: 'scroll'
});

Both libraries offer simple ways to add scroll-based effects, but Jarallax provides more options for parallax animations. ScrollReveal focuses on revealing elements as they enter the viewport, while Jarallax can create various parallax effects, including background image parallax.

ScrollReveal is ideal for projects that primarily need element reveal animations on scroll, whereas Jarallax is better suited for websites requiring diverse parallax effects and more advanced scroll-based animations.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Jarallax

jarallax.min.js jarallax-video.min.js

Parallax scrolling for modern browsers. Supported <img> tags, background images, YouTube, Vimeo and Self-Hosted Videos.

Online Demo

Table of Contents

WordPress Plugin

Advanced WordPress Backgrounds

We made WordPress plugin to easily add backgrounds for content in your blog with all Jarallax features.

Demo: https://wpbackgrounds.com/

Download: https://wordpress.org/plugins/advanced-backgrounds/

Quick Start

There are a set of examples, which you can use as a starting point with Jarallax.

Import Jarallax

Use one of the following examples to import jarallax.

ESM

We provide a version of Jarallax built as ESM (jarallax.esm.js and jarallax.esm.min.js) which allows you to use Jarallax as a module in your browser, if your targeted browsers support it.

<!-- Jarallax CSS -->
<link href="jarallax.min.css" rel="stylesheet">

<!-- Jarallax JS -->
<script type="module">
  import { jarallax, jarallaxVideo } from "jarallax.esm.min.js";

  // Optional video extension
  jarallaxVideo();
</script>

ESM CDN

<!-- Jarallax CSS -->
<link href="https://cdn.jsdelivr.net/npm/jarallax@2/dist/jarallax.min.css" rel="stylesheet">

<!-- Jarallax JS -->
<script type="module">
  import { jarallax, jarallaxVideo } from "https://cdn.jsdelivr.net/npm/jarallax@2/+esm";

  // Optional video extension
  jarallaxVideo();
</script>

UMD

Jarallax may be also used in a traditional way by including script in HTML and using library by accessing window.jarallax.

<!-- Jarallax CSS -->
<link href="jarallax.min.css" rel="stylesheet">

<!-- Jarallax JS -->
<script src="jarallax.min.js"></script>

<!-- Jarallax JS: Optional video extension -->
<script src="jarallax-video.min.js"></script>

UMD CDN

<!-- Jarallax CSS -->
<link href="https://cdn.jsdelivr.net/npm/jarallax@2/dist/jarallax.min.css" rel="stylesheet">

<!-- Jarallax JS -->
<script src="https://cdn.jsdelivr.net/npm/jarallax@2/dist/jarallax.min.js"></script>

<!-- Jarallax JS: Optional video extension -->
<script src="https://cdn.jsdelivr.net/npm/jarallax@2/dist/jarallax-video.min.js"></script>

CJS (Bundlers like Webpack)

Install Jarallax as a Node.js module using npm

npm install jarallax

Import Jarallax by adding this line to your app's entry point (usually index.js or app.js):

import { jarallax, jarallaxVideo } from "jarallax";
import 'jarallax/dist/jarallax.min.css';

// Optional video extension
jarallaxVideo();

Prepare HTML

<!-- Background Image Parallax -->
<div class="jarallax">
  <img class="jarallax-img" src="<background_image_url_here>" alt="">
  Your content here...
</div>

<!-- Background Image Parallax with <picture> tag -->
<div class="jarallax">
  <picture class="jarallax-img">
    <source media="..." srcset="<alternative_background_image_url_here>">
    <img src="<background_image_url_here>" alt="">
  </picture>
  Your content here...
</div>

<!-- Alternate: Background Image Parallax -->
<div class="jarallax" style="background-image: url('<background_image_url_here>');">
  Your content here...
</div>

Run Jarallax

Note: automatic data-attribute initialization and jQuery integration are available in UMD mode only.

A. JavaScript way

jarallax(document.querySelectorAll('.jarallax'), {
  speed: 0.2,
});

B. Data attribute way

<div data-jarallax data-speed="0.2" class="jarallax">
  <img class="jarallax-img" src="<background_image_url_here>" alt="">
  Your content here...
</div>

Note: You can use all available options as data attributes. For example: data-speed, data-img-src, data-img-size, etc...

C. jQuery way

$('.jarallax').jarallax({
  speed: 0.2,
});

No conflict (only if you use jQuery)

Sometimes to prevent existing namespace collisions you may call .noConflict on the script to revert the value of.

const jarallaxPlugin = $.fn.jarallax.noConflict() // return $.fn.jarallax to previously assigned value
$.fn.newJarallax = jarallaxPlugin // give $().newJarallax the Jarallax functionality

Background Video Usage Examples

A. JavaScript way

import { jarallax, jarallaxVideo } from 'jarallax';
jarallaxVideo();

jarallax(document.querySelectorAll('.jarallax'), {
  speed: 0.2,
  videoSrc: 'https://www.youtube.com/watch?v=ab0TSkLe-E0'
});
<div class="jarallax"></div>

B. Data attribute way

<!-- Background YouTube Parallax -->
<div class="jarallax" data-jarallax data-video-src="https://www.youtube.com/watch?v=ab0TSkLe-E0">
  Your content here...
</div>

<!-- Background Vimeo Parallax -->
<div class="jarallax" data-jarallax data-video-src="https://vimeo.com/110138539">
  Your content here...
</div>

<!-- Background Self-Hosted Video Parallax -->
<div class="jarallax" data-jarallax data-video-src="mp4:./video/local-video.mp4,webm:./video/local-video.webm,ogv:./video/local-video.ogv">
  Your content here...
</div>

Note: self-hosted videos require 1 video type only, not necessarily using all mp4, webm, and ogv. This is only needed for maximum compatibility with all browsers.

Options

Options can be passed in data attributes or in object when you initialize jarallax from script.

NameTypeDefaultDescription
typestringscrollscroll, scale, opacity, scroll-opacity, scale-opacity.
speedfloat0.5Parallax effect speed. Provide numbers from -1.0 to 2.0.
containerClassstringjarallax-containerContainer block class attribute.
imgSrcpathnullImage url. By default used image from background.
imgElementdom / selector.jarallax-imgImage tag that will be used as background.
imgSizestringcoverImage size. If you use <img> tag for background, you should add object-fit values, else use background-size values.
imgPositionstring50% 50%Image position. If you use <img> tag for background, you should add object-position values, else use background-position values.
imgRepeatstringno-repeatImage repeat. Supported only background-position values.
keepImgbooleanfalseKeep <img> tag in it's default place after Jarallax inited.
elementInViewportdomnullUse custom DOM / jQuery element to check if parallax block in viewport. More info here - Issue 13.
zIndexnumber-100z-index of parallax container.
disableParallaxboolean / RegExp / function-Disable parallax on specific user agents (using regular expression) or with function return value. The image will be set on the background.

Disable on mobile devices

You can disable parallax effect and/or video background on mobile devices using option disableParallax and/or disableVideo.

Example:

jarallax(document.querySelectorAll('.jarallax'), {
  disableParallax: /iPad|iPhone|iPod|Android/,
  disableVideo: /iPad|iPhone|iPod|Android/
});

Or using function. Example:

jarallax(document.querySelectorAll('.jarallax'), {
  disableParallax: function () {
    return /iPad|iPhone|iPod|Android/.test(navigator.userAgent);
  },
  disableVideo: function () {
    return /iPad|iPhone|iPod|Android/.test(navigator.userAgent);
  }
});

Additional options for video extension

Required jarallax/jarallax-video.js file.

NameTypeDefaultDescription
videoClassstringjarallax-videoVideo frame class attribute. Will also contain the type of the video, for example jarallax-video jarallax-video-youtube
videoSrcstringnullYou can use Youtube, Vimeo or Self-Hosted videos. Also you can use data attribute data-jarallax-video.
videoStartTimefloat0Start time in seconds when video will be started (this value will be applied also after loop).
videoEndTimefloat0End time in seconds when video will be ended.
videoLoopbooleantrueLoop video to play infinitely.
videoPlayOnlyVisiblebooleantruePlay video only when it is visible on the screen.
videoLazyLoadingbooleantruePreload videos only when it is visible on the screen.
disableVideoboolean / RegExp / function-Disable video load on specific user agents (using regular expression) or with function return value. The image will be set on the background.

Events

Events used the same way as Options.

NameDescription
onScrollCalled when parallax working. Use first argument with calculations. More info see below.
onInitCalled after init end.
onDestroyCalled after destroy.
onCoverImageCalled after cover image.

Additional events for video extension

Required jarallax/jarallax-video.js file.

NameDescription
onVideoInsertCalled right after video is inserted in the parallax block. Video can be accessed by this.$video
onVideoWorkerInitCalled after VideoWorker script initialized. Available parameter with videoWorkerObject.

onScroll event

jarallax(document.querySelectorAll('.jarallax'), {
  onScroll: function(calculations) {
    console.log(calculations);
  }
});

Console Result:

{
  // parallax section client rect (top, left, width, height)
  rect            : object,

  // see image below for more info
  beforeTop       : float,
  beforeTopEnd    : float,
  afterTop        : float,
  beforeBottom    : float,
  beforeBottomEnd : float,
  afterBottom     : float,

  // percent of visible part of section (from 0 to 1)
  visiblePercent  : float,

  // percent of block position relative to center of viewport from -1 to 1
  fromViewportCenter: float
}

Calculations example: On Scroll Calculations

Methods

NameResultDescription
destroy-Destroy Jarallax and set block as it was before plugin init.
isVisiblebooleanCheck if parallax block is in viewport.
onResize-Fit image and clip parallax container. Called on window resize and load.
onScroll-Calculate parallax image position. Called on window scroll.

Call methods example

A. JavaScript way

jarallax(document.querySelectorAll('.jarallax'), 'destroy');

B. jQuery way

$('.jarallax').jarallax('destroy');

For Developers

Installation

  • Run npm install in the command line

Building

  • npm run dev to run build and start local server with files watcher
  • npm run build to run build

Linting

  • npm run js-lint to show eslint errors
  • npm run js-lint-fix to automatically fix some of the eslint errors

Test

  • npm run test to run unit tests

Real Usage Examples

Credits

NPM DownloadsLast 30 Days