Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. $(window).on('scroll', function() {
  2. $.throttle(100, sectionScroll));
  3. });
  4.  
  5. sectionScroll = function() {
  6. var lastScrollTop = 0, delta = 5;
  7. var left = $('.layout__left');
  8. var right = $('.layout__right');
  9. var scroll = $(this).scrollTop();
  10. var viewport = $(window).height();
  11. var lastChild = $('.navigation > ul > li:last-child').offset().top;
  12.  
  13. if(Math.abs(lastScrollTop - scroll) <= delta)
  14. return;
  15.  
  16. if (scroll > lastScrollTop){
  17. // SCROLL DOWN
  18. left.removeClass('top absolute');
  19.  
  20. // if the last item of the left is visible
  21. if ( (scroll + viewport) > (lastChild + 30) ) {
  22. // make the left fixed
  23. left.addClass('fixed bottom');
  24. console.log("bottom!");
  25. }
  26.  
  27. // SCROLL UP
  28. } else {
  29. // remove fixed class from left
  30. left.removeClass('fixed bottom');
  31. left.addClass('absolute bottom');
  32.  
  33. if ( scroll <= left.position().top ) {
  34. left.removeClass('bottom absolute');
  35. left.addClass('top fixed');
  36. left.removeClass('top fixed');
  37. console.log("top!");
  38. }
  39. }
  40.  
  41. lastScrollTop = scroll;
  42. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement