Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function($) {
- var $container = $(".parallax");
- var $divs = $container.find("div.parallax-background");
- var elementBeingScrolled = document.body;
- console.log("Element being scrolled: "+elementBeingScrolled);
- var liHeight = $divs.eq(0).closest("li").height();
- var diffHeight = $divs.eq(0).height() - liHeight;
- console.log($divs);
- var i, len, div, li, offset, scroll, top;
- var render = function() {
- top = elementBeingScrolled.scrollTop;
- //loop through divs
- for (i=0,len=$divs.length;i<len;i++) {
- // get one div
- div = $divs[i];
- // get the parent li
- li = div.parentNode;
- // calculate the offset TOP of div
- offset = $(div).offset().top;
- // calculate the amount to scroll
- scroll = Math.round(((top - offset) / liHeight) * diffHeight);
- // apply
- div.style.webkitTransform = "translate3d(0px," + scroll + "px,0px)";
- }
- };
- (function loop() {
- requestAnimationFrame(loop);
- render();
- })();
- })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement