- Click here to download parallax.js
document.addEventListener('DOMContentLoaded', function() {
function initializeParallax() {
document.querySelectorAll('.parallax').forEach(function(el) {
new parallax({ el: el });
});
}
initializeParallax();
window.addEventListener('pronto.render', function(event) {
initializeParallax();
});
});
- el : null
- css : “background-position”
- speed: 1
- position: “center”
- moveBy: “percent”
- preventIfLarge: false
Options
El
This option is required. The javascript object you want the effect attached to
CSS
This variable has two options, “background-position” & “object-position”. background-position will apply the effect to a background image while object-position will apply the effect to an “img” tag.
Speed
Effects how much the parallax affects the image
Position
This will affect the background-position “left” or “right” position.
moveBy
This variable has two options, “percent” & “px”. This will move the image either by percents or pixels.
preventIfLarge
This is a boolean variable. If the image element is larger than the the viewport, it may not scroll correctly. If the image itself is still large enough, than sometimes it works, but if its set to false, it will default the position to “50%”, or essentially center.
