Created
November 19, 2021 04:39
-
-
Save Alexander-Pop/0f281688be2a94a8901c45af0f4c34a0 to your computer and use it in GitHub Desktop.
Play with Parallax #parallax #js $jq #animation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const main = {}; | |
const updateScroll = () => { | |
main.winScroll = $(window).scrollTop(); | |
}; | |
const parallaxLoad = () => { | |
const $someEl = $('.someEl'); | |
$someEl.each((i,el) => { | |
let $el = $(el); | |
main.someEl[i] = $el; | |
}); | |
} | |
const parallaxScroll = () => { | |
$.each(main.someEl, (i,$el) => { | |
$el.imgPos = (main.winScroll - $el.offset().top) / 20; | |
$el.css('transform', 'translateY(' + $el.imgPos + '%)'); | |
}); | |
} | |
// Compile | |
const load = () => { | |
parallaxLoad(); | |
} | |
const scroll = () => { | |
updateScroll(); | |
parallaxScroll(); | |
} | |
// Events | |
$(window).scroll(() => { | |
scroll(); | |
}); | |
load(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment