Easy parallax plugin using vanilla javascript. Works on mobile devices (really). Lightweight (2kb). Cross browser compatibility
npm install universal-parallax
   
#### See demo
$ npm i universal-parallax -S#### #1
_Choose between:_
- Include this in your section
``html`
- Or add this CSS
`css
.parallax__container {
clip: rect(0, auto, auto, 0);
height: 100%;
left: 0;
overflow: hidden;
position: absolute;
top: 0;
width: 100%;
z-index: -100;
}
.parallax {
position: fixed;
top: 0;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
width: 100%;
/ BG behaviour /
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
`
:zap: _BG behaviour in seperate class gives more flexibility controlling them_
:zap: _SASS version available in /dist folder_
#### #2
If is your container, make the parallax element inside it
` :zap: You can also use #### #3 #### #4 --- :zap: #### Opacityhtml
`background-image to define your image instead of using data-parallax-image=""`
Include the script to your projecthtml``
Initialize the JS functionhtml``
That's it! :checkered_flag:
- If it resembles the demo - you're done :tada:
- See customizations underneath
- Please report any problems you find
- Otherwise, let me know me for new features or improvements. Thanks!Custom speed
You can change the parallax speed; the higher the number, the slower the parallax effectjs`
new universalParallax().init({
speed: 6.0
});speed: 1 is the minimum value before the background image is fixed`Tips
If you want your backround color to shine through or dampen the image without making it a .png - just add transparency to itcss``
.parallax {
opacity: 0.5;
}