diff --git a/index.html b/index.html index 08a1e53..9dcb446 100644 --- a/index.html +++ b/index.html @@ -51,7 +51,7 @@ -
+
bg-img
diff --git a/lib/js/index.js b/lib/js/index.js index 396ae27..aceb551 100644 --- a/lib/js/index.js +++ b/lib/js/index.js @@ -1,10 +1,14 @@ // Parallax -const depthFactor = 3; // Depth of the image wrt to the 0 z-index. 1 being at the same distance as the rest of the content and Infinity being as far away as possible. +const depthFactor = 5; // Depth of the image wrt to the 0 z-index. 1 being at the same distance as the rest of the content and Infinity being as far away as possible. $(window).on('scroll', () => { const movedBy = window.scrollY; - $('.parallax .parallax-img').css({ - transform: `translateY(${movedBy / depthFactor}px)` // Move differently than the rest of the window + $('.parallax').each((i, elem) => { + const depth = $(elem).attr('data-depth-factor') || depthFactor; // dynamically get depthFactor + + $(elem).find('.parallax-img').css({ + transform: `translateY(${movedBy / depth}px)` // Move differently than the rest of the window + }) }) }) // /Parallax