Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(window).on('scroll', function() {
- $.throttle(100, sectionScroll));
- });
- sectionScroll = function() {
- var lastScrollTop = 0, delta = 5;
- var left = $('.layout__left');
- var right = $('.layout__right');
- var scroll = $(this).scrollTop();
- var viewport = $(window).height();
- var lastChild = $('.navigation > ul > li:last-child').offset().top;
- if(Math.abs(lastScrollTop - scroll) <= delta)
- return;
- if (scroll > lastScrollTop){
- // SCROLL DOWN
- left.removeClass('top absolute');
- // if the last item of the left is visible
- if ( (scroll + viewport) > (lastChild + 30) ) {
- // make the left fixed
- left.addClass('fixed bottom');
- console.log("bottom!");
- }
- // SCROLL UP
- } else {
- // remove fixed class from left
- left.removeClass('fixed bottom');
- left.addClass('absolute bottom');
- if ( scroll <= left.position().top ) {
- left.removeClass('bottom absolute');
- left.addClass('top fixed');
- left.removeClass('top fixed');
- console.log("top!");
- }
- }
- lastScrollTop = scroll;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement