Pure Parallaxify
Add depth to your project!
pure parallaxify is a vanilla js plugin that adds parallax effects to elements and backgrounds based on mouse movement.
Download
You can install this plugin using npm
or yarn
:
npm install pure-parallaxify
or
yarn add pure-parallaxify
Or you can use the CDN in your HTML:
<script src="https://cdn.jsdelivr.net/npm/pure-parallaxify@0.0.4/dist/pure.parallaxify.js"></script>
Get things going
In order to add a parallax effect to any element you can run new Parallaxify()
on the wrapper of an element or run it globally on window
:
new Parallaxify({}, "#my-wrapper");
new Parallaxify();
But, first, you need to add one of these attributes to your tags to detected by Parallaxify:
data-parallaxify-range
data-parallaxify-range-x
data-parallaxify-range-y
<div data-parallaxify-range-x="50" data-parallaxify-range-y="100"></div>
Customize the plugin
Pure Parallaxify exposes a variety of options that let you influence how element positioning is achieved, configure filtering of sensor data, configure the movement algorithm, and change general plugin settings.
new Parallaxify({
horizontalParallax: true,
verticalParallax: true,
parallaxBackgrounds: true,
parallaxElements: true,
positionProperty: "position",
responsive: false,
useMouseMove: true,
useGyroscope: true,
alphaFilter: 0.9,
motionType: "natural",
mouseMotionType: "gaussian",
inputPriority: "mouse",
motionAngleX: 80,
motionAngleY: 80,
adjustBasePosition: true,
alphaPosition: 0.05,
});
License
Released under the MIT license.
Thanks
I have used Felix Pflaum's Parallaxify plugin for jQuery. So I did refactored some parts and published it for vanilla js to be used in other frameworks too.