Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions parascroll.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
document.addEventListener("DOMContentLoaded", function(){
var CLASS_NAME = ".parallax-bg";
var ATTR_NAME = "data-bgurl";
var SCROLL_SPEED = 0.6;
document.addEventListener("DOMContentLoaded", () => {
const className = ".parallax";
const attrName = "data-bgurl";
const scrollSpeed = 0.6;
const elements = document.querySelectorAll(className);
const targets = [];

var elements = document.querySelectorAll(CLASS_NAME);
var targets = [];
for (var i = 0; i < elements.length; i++) {
var elem = elements[i];
var url = elem.getAttribute(ATTR_NAME);
elements.forEach(elem => {
const url = elem.getAttribute(attrName);
if (url) {
elem.style.backgroundImage = "url('"+url+"')";
elem.style.backgroundImage = "url('" + url + "')";
elem.style.backgroundAttachment = "fixed";
elem.style.backgroundSize = "cover";
targets.push(elem);
}
}
var callback = function() {
for (var i = 0; i < targets.length; i++) {
var rekt = targets[i].getBoundingClientRect();
});

const callback = () => {
for (let i = 0; i < targets.length; i++) {
const rect = targets[i].getBoundingClientRect();
targets[i].style.backgroundPosition = "50%" +
rekt.top*SCROLL_SPEED + "px";
rect.top * scrollSpeed + "px";
}
};

window.onscroll = callback;
callback();
});
2 changes: 1 addition & 1 deletion parascroll.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.