Jarallax is a dependency-free smooth video & image parallax scrolling. It is built with pure JavaScript and CSS3 so you can modify the styling and appearance of the plugin according to your requirements. There are various types of predefined options and you can apply these easily to modify the plugin.
npm install jarallax --save
import {
jarallax,
jarallaxVideo
} from 'jarallax';
jarallaxVideo();
1. Include the Javascript jarallax.min.js
at the bottom of the web page.
<script src="path/to/jarallax.min.js"></script>
2. Include the CSS jarallax.css
in the header of the page.
<link rel="stylesheet" href="path/to/jarallax.css">
Or you can alternatively add the CSS to your existing .css file.
.jarallax {
position: relative;
z-index: 0;
}
.jarallax > .jarallax-img {
position: absolute;
object-fit: cover;
/* support for plugin https://github.com/bfred-it/object-fit-images */
font-family: 'object-fit: cover;';
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
3. Add the basic HTML to the page.
<!-- 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>
4. Initialize the plugin and we're ready to go.
$('.jarallax').jarallax({
speed: 0.2
});
<!-- Background YouTube Parallax -->
<div class="jarallax" data-jarallax-video="https://www.youtube.com/watch?v=ab0TSkLe-E0">
Your content here...
</div>
<!-- Background Vimeo Parallax -->
<div class="jarallax" data-jarallax-video="https://vimeo.com/110138539">
Your content here...
</div>
<!-- Background Self-Hosted Video Parallax -->
<div class="jarallax" data-jarallax-video="mp4:./video/local-video.mp4,webm:./video/local-video.webm,ogv:./video/local-video.ogv">
Your content here...
</div>
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>
Name | Type | Default | Description |
---|---|---|---|
type | string | scroll |
scroll, scale, opacity, scroll-opacity, scale-opacity. |
speed | float | 0.5 |
Parallax effect speed. Provide numbers from -1.0 to 2.0. |
imgSrc | path | null |
Image url. By default used image from background. |
imgElement | dom / selector | .jarallax-img |
Image tag that will be used as background. |
imgSize | string | cover |
Image size. If you use <img> tag for background, you should add object-fit values, else use background-size values. |
imgPosition | string | 50% 50% |
Image position. If you use <img> tag for background, you should add object-position values, else use background-position values. |
imgRepeat | string | no-repeat |
Image repeat. Supported only background-position values. |
keepImg | boolean | false |
Keep <img> tag in it's default place after Jarallax inited. |
elementInViewport | dom | null |
Use custom DOM / jQuery element to check if parallax block in viewport. More info here - Issue 13. |
zIndex | number | -100 |
z-index of parallax container. |
disableParallax | RegExp / function | - | Disable parallax on specific user agents (using regular expression) or with function return value. The image will be set on the background. |
disableVideo | 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. |
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);
}
});
Required jarallax/jarallax-video.js
file.
Name | Type | Default | Description |
---|---|---|---|
videoSrc | string | null |
You can use Youtube, Vimeo or Self-Hosted videos. Also you can use data attribute data-jarallax-video . |
videoStartTime | float | 0 |
Start time in seconds when video will be started (this value will be applied also after loop). |
videoEndTime | float | 0 |
End time in seconds when video will be ended. |
videoVolume | float | 0 |
Video volume from 0 to 100. |
videoLoop | boolean | true |
Loop video to play infinitely. |
videoPlayOnlyVisible | boolean | true |
Play video only when it is visible on the screen. |
videoLazyLoading | boolean | true |
Preload videos only when it is visible on the screen. |
Required jarallax/jarallax-element.js
file.
Name | Type | Default | Description |
---|---|---|---|
type | string | element |
Will only work with element value. |
speed | mixed | 0 0 |
Parallax distance in pixels. Supported Y and X axis. Example: 100 200 . Also you can use data attribute data-jarallax-element . |
threshold | mixed | null null |
Specify threshold for the parallax effect to kick in. For example, if you pass 0 0 , the element will start to move only after it has been scrolled to the middle of the viewport. |
Name | Description |
---|---|
onScroll | Called when parallax working. Use first argument with calculations. More info see below. |
onInit | Called after init end. |
onDestroy | Called after destroy. |
onCoverImage | Called after cover image. |
jarallax(document.querySelectorAll('.jarallax'), {
onScroll: function(calculations) {
console.log(calculations);
}
});
Name | Result | Description |
---|---|---|
destroy | - | Destroy Jarallax and set block as it was before plugin init. |
isVisible | boolean | Check 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. |
jarallax(document.querySelectorAll('.jarallax'), 'destroy');
$('.jarallax').jarallax('destroy');
<div data-jarallax data-speed="0.2" class="jarallax">
<img class="jarallax-img" src="path/to/images/demo-3.jpg" alt="">
Your content here...
</div>
<div class="jarallax" data-jarallax data-speed="0.2">
<img class="jarallax-img" src="path/to/images/demo.jpg" alt="">
</div>
<div class="jarallax" data-jarallax data-speed="-0.2">
<img class="jarallax-img" src="path/to/images/demo.jpg" alt="">
</div>
<div class="jarallax" data-jarallax data-speed="1.4">
<img class="jarallax-img" src="path/to/images/demo.jpg" alt="">
</div>
So Give doesn't forth male him. God cattle rule Heaven blessed Beast lesser him so. Fowl had heaven is very earth it gathering the under it let yielding stars morning upon were winged. Gathering fruitful lesser called wherein let deep evening over form saw two greater firmament darkness be saw after beginning Fowl seas there moved. Their moveth she'd had you all were tree good winged midst from. Light you'll fill. Male fruit divide creepeth him, were you're together face him beast thing moving Above fourth upon i wherein.
Created life set may don't. Moving living tree the firmament signs fifth place fruit fowl was a own third great set all so for first light our signs can't creeping itself every the without let given saw whose. Divided signs that gathering. Great itself. Dry make night. A you're he behold thing evening his morning. The wherein kind he open fruitful without whales sea said, winged day. Green own in female deep the i. Days stars lights, fill seas two darkness for meat fourth evening living saw morning given. Form have make in heaven was fill Night make. You moving third. Of above dominion spirit living creature multiply. Third over third seasons our sixth.
Fifth green, they're moved creeping years, man. Fifth, be To there were over together sixth fish heaven sea. Spirit may is unto second that seasons without. Darkness whose day fruit rule firmament Whales. Fourth replenish dominion. After subdue creature in sea morning. Green moved, rule female be, over night saying life there first forth that, may stars above divided moving shall. Together deep meat image subdue you created be two. Thing their you're great gathering male day divide. Moveth said deep.
Winged upon one were you given. Bearing lights deep meat a bring fish female. Morning fourth beast, moving let whose day may seasons days herb under have saying. Upon isn't abundantly beast, give dry moved, together midst land whales. Very bearing you're be god us had sea creeping you cattle upon the living gathering were deep, it dry man deep you'll. Unto she'd one fowl replenish shall winged also hath morning. Third bearing wherein one.
<div class="jarallax-keep-img demo-float-left" data-jarallax data-speed="0.5">
<img class="jarallax-img" src="path/to/images/demo.jpg" alt="" width="400">
</div>
jarallax(document.querySelectorAll('.jarallax-keep-img'), {
keepImg: true,
});
<div class="jarallax" data-jarallax data-speed="0.5" data-video-src="https://youtu.be/mru3Q5m4lkY"></div>
<div class="jarallax" data-jarallax data-speed="-0.5" data-video-src="mp4:path/to/video/local-video.mp4,webm:path/to/video/local-video.webm,ogv:path/to/video/local-video.ogv">
<img data-jarallax data-speed="-0.5" class="jarallax-img" src="path/to/images/local-video.png" alt="">
</div>
<div class="jarallax" data-jarallax data-speed="1.2" data-video-src="https://vimeo.com/235212527"></div>
<div class="demo-gap-half">
<div class="demo-gap-1">
<div class="jarallax" data-jarallax data-speed="0.2">
<img class="jarallax-img" src="path/to/images/demo.jpg" alt="">
</div>
</div>
<div class="demo-gap-2" data-jarallax data-speed="0">
<div class="jarallax">
<img class="jarallax-img" src="path/to/images/demo.jpg" alt="">
</div>
<div class="jarallax" data-jarallax data-speed="1.4">
<img class="jarallax-img" src="path/to/images/demo.jpg" alt="">
</div>
</div>
</div>
Images https://unsplash.com/ | Videos https://videos.pexels.com/