Advertisement
Guest User

Untitled

a guest
Jul 17th, 2014
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.45 KB | None | 0 0
  1. (function($) {
  2.                 var $container = $(".parallax");
  3.                 var $divs = $container.find("div.parallax-background");
  4.                 var elementBeingScrolled = document.body;
  5.                 console.log("Element being scrolled: "+elementBeingScrolled);
  6.                 var liHeight = $divs.eq(0).closest("li").height();
  7.                 var diffHeight = $divs.eq(0).height() - liHeight;
  8.                 console.log($divs);
  9.                 var i, len, div, li, offset, scroll, top;
  10.                 var render = function() {
  11.                     top = elementBeingScrolled.scrollTop;
  12.                     //loop through divs
  13.                     for (i=0,len=$divs.length;i<len;i++) {
  14.                         // get one div
  15.                         div = $divs[i];
  16.                         // get the parent li
  17.                         li = div.parentNode;
  18.                         // calculate the offset TOP of div
  19.                         offset = $(div).offset().top;
  20.                         // calculate the amount to scroll
  21.                         scroll = Math.round(((top - offset) / liHeight) * diffHeight);
  22.                         // apply
  23.                         div.style.webkitTransform = "translate3d(0px," + scroll + "px,0px)";
  24.                     }
  25.                 };
  26.  
  27.                 (function loop() {
  28.                     requestAnimationFrame(loop);
  29.                     render();
  30.                 })();
  31.             })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement