src/components/sticky/sticky.js
function onScroll() {
      var scrollTop = contentEl.prop('scrollTop');
      var isScrollingDown = scrollTop > (onScroll.prevScrollTop || 0);

      // Store the previous scroll so we know which direction we are scrolling
      onScroll.prevScrollTop = scrollTop;

      //
      // AT TOP (not scrolling)
      //
      if (scrollTop === 0) {
        // If we're at the top, just clear the current item and return
        setCurrentItem(null);
        return;
      }

      //
      // SCROLLING DOWN (going towards the next item)
      //
      if (isScrollingDown) {

        // If we've scrolled down past the next item's position, sticky it and return
        if (self.next && self.next.top <= scrollTop) {
          setCurrentItem(self.next);
          return;
        }

        // If the next item is close to the current one, push the current one up out of the way
        if (self.current && self.next && self.next.top - scrollTop <= self.next.height) {
          translate(self.current, scrollTop + (self.next.top - self.next.height - scrollTop));
          return;
        }
      }

      //
      // SCROLLING UP (not at the top & not scrolling down; must be scrolling up)
      //
      if (!isScrollingDown) {

        // If we've scrolled up past the previous item's position, sticky it and return
        if (self.current && self.prev && scrollTop < self.current.top) {
          setCurrentItem(self.prev);
          return;
        }

        // If the next item is close to the current one, pull the current one down into view
        if (self.next && self.current && (scrollTop >= (self.next.top - self.current.height))) {
          translate(self.current, scrollTop + (self.next.top - scrollTop - self.current.height));
          return;
        }
      }

      //
      // Otherwise, just move the current item to the proper place (scrolling up or down)
      //
      if (self.current) {
        translate(self.current, scrollTop);
      }
    }
function onScroll() {
      var scrollTop = contentEl.prop('scrollTop');
      var isScrollingDown = scrollTop > (onScroll.prevScrollTop || 0);

      // Store the previous scroll so we know which direction we are scrolling
      onScroll.prevScrollTop = scrollTop;

      //
      // AT TOP (not scrolling)
      //
      if (scrollTop === 0) {
        // If we're at the top, just clear the current item and return
        setCurrentItem(null);
        return;
      }

      //
      // SCROLLING DOWN (going towards the next item)
      //
      if (isScrollingDown) {

        // If we've scrolled down past the next item's position, sticky it and return
        if (self.next && self.next.top <= scrollTop) {
          setCurrentItem(self.next);
          return;
        }

        // If the next item is close to the current one, push the current one up out of the way
        if (self.current && self.next && self.next.top - scrollTop <= self.next.height) {
          translate(self.current, scrollTop + (self.next.top - self.next.height - scrollTop));
          return;
        }
      }

      //
      // SCROLLING UP (not at the top & not scrolling down; must be scrolling up)
      //
      if (!isScrollingDown) {

        // If we've scrolled up past the previous item's position, sticky it and return
        if (self.current && self.prev && scrollTop < self.current.top) {
          setCurrentItem(self.prev);
          return;
        }

        // If the next item is close to the current one, pull the current one down into view
        if (self.next && self.current && (scrollTop >= (self.next.top - self.current.height))) {
          translate(self.current, scrollTop + (self.next.top - scrollTop - self.current.height));
          return;
        }
      }

      //
      // Otherwise, just move the current item to the proper place (scrolling up or down)
      //
      if (self.current) {
        translate(self.current, scrollTop);
      }
    }
function onScroll ( ) { var scrollTop = contentEl . prop ( 'scrollTop' ) ; var isScrollingDown = scrollTop > ( onScroll . prevScrollTop || 0 ) ; // Store the previous scroll so we know which direction we are scrolling onScroll . prevScrollTop = scrollTop ; // // AT TOP (not scrolling) // if ( scrollTop === 0 ) { // If we're at the top, just clear the current item and return setCurrentItem ( null ) ; return ; } // // SCROLLING DOWN (going towards the next item) // if ( isScrollingDown ) { // If we've scrolled down past the next item's position, sticky it and return if ( self . next && self . next . top <= scrollTop ) { setCurrentItem ( self . next ) ; return ; } // If the next item is close to the current one, push the current one up out of the way if ( self . current && self . next && self . next . top - scrollTop <= self . next . height ) { translate ( self . current , scrollTop + ( self . next . top - self . next . height - scrollTop ) ) ; return ; } } // // SCROLLING UP (not at the top & not scrolling down; must be scrolling up) // if ( ! isScrollingDown ) { // If we've scrolled up past the previous item's position, sticky it and return if ( self . current && self . prev && scrollTop < self . current . top ) { setCurrentItem ( self . prev ) ; return ; } // If the next item is close to the current one, pull the current one down into view if ( self . next && self . current && ( scrollTop >= ( self . next . top - self . current . height ) ) ) { translate ( self . current , scrollTop + ( self . next . top - scrollTop - self . current . height ) ) ; return ; } } // // Otherwise, just move the current item to the proper place (scrolling up or down) // if ( self . current ) { translate ( self . current , scrollTop ) ; } }
As we scroll, push in and select the correct sticky element.
As we scroll push in and select the correct sticky element .