A library for parallax scrolling images, videos, divs etc by using the height of the element and with the window scroll offset
A library for giving a parallax scrolling effect to elements (div, img, video etc). Simply add the default class .parallax-element
or set your own identifier: '.your-class'
to any element you want to parallax.
Please help the development by reporting any bugs. Also feel free to contribute to this project. Thanks ❤
<script src="https://unpkg.com/bparallax/src/bparallax.js">
npm i bparallax
Your parallax elements:
<img class="parallax-element" src='...'>
// or
<video class="parallax-element">
<source src="...">
</video>
// or
<div class="parallax-element" style="background-image: url(...)">
Then in javascript:
// If you use the CDN
BoxParallaxScroll().init();
// If you use NPM or a Framework
import BoxParallaxScroll from 'bparallax';
BoxParallaxScroll().init();
// Default values
BoxParallaxScroll({
identifier: ".parallax-element",
strechFactor: 0.2
}).init();
identifier
: [string]
strechFactor
: [float] [0 to 1]
BoxParallaxScroll creates a wrapper with the class .wrapper
and sets the parallaxable element as it’s child.
/* Use this for the images you want to parallax */
.parallax-element{
object-fit: cover; // Fixes image ratio
}