garand / sticky

jQuery Plugin for Sticky Objects
Other
3.3k stars 1.06k forks source link

HOW TO: Stick element to parent container? #257

Open ghost opened 7 years ago

ghost commented 7 years ago

Hi! HOW TO: Stick element to parent container?

<div class="col-md-12">
   <div class="col-md-8">
      <div class="menu" id="sticky"></div>
   </div>
</div>

And how to stick element to col-md-12 class?

Tsiftelis-Thanasis commented 7 years ago

Hi! i am having the same issue, any update? Thanks!

kytosai commented 6 years ago

Guide: You can change core sticky file to use bottomSpacing with function to check destination point pause sticky

Edit file sticky.js file: http://prntscr.com/hnrb6e Change old line

var newTop = documentHeight - s.stickyElement.outerHeight()
            - s.topSpacing - s.bottomSpacing - scrollTop - extra;

To

 // EDIT
          var newTop =  documentHeight - s.stickyElement.outerHeight()
            - s.topSpacing - scrollTop - extra;

          if (typeof s.bottomSpacing === 'function') {
            newTop = newTop - s.bottomSpacing();
          }else {
            newTop = newTop - s.bottomSpacing;
          }
          // END EDIT

Use new config bottomSpacing with function check end point: http://prntscr.com/hnrcd3

$('#examp-sticky').sticky({
        bottomSpacing: function(){
          return $('html').height() - $('.fake-end-point').offset().top;
        },
      });