bigspotteddog / ScrollToFixed

This plugin is used to fix elements on the page (top, bottom, anywhere); however, it still allows the element to continue to move left or right with the horizontal scroll.
http://bigspotteddog.github.com/ScrollToFixed/
MIT License
1.81k stars 532 forks source link

delay fixing until scroll value is reached #101

Open ebillias opened 11 years ago

ebillias commented 11 years ago

was wondering if I could delay the header from attaching to the window until the user has scrolled say 100px, maybe something to do with scrollTop > 100 ?? not sure how to add this condition to scrollToFixed function

bigspotteddog commented 11 years ago

The marginTop property can be a function as well; kind of like the limit property. That will be run for each scroll event. Maybe you can test for the scroll position in that function, then return the scrollTop when it meets your criteria. I have not tried this yet, but I will give it a try when I get a chance in a fiddle.

Best of luck and I hope that helps.

HybridSolutions commented 10 years ago

I also trying to accomplish this. Anyone has a concrete idea on how to do it? Thank you.

jenpapa commented 8 years ago

I recently had this same need and was able to use the marginTop function to accomplish it. Fiddle: http://jsfiddle.net/jenpapa/by7uetvy/1/

$(document).ready(function() {
  $('#cart').scrollToFixed({
    marginTop: function() {
      var fix_at_me_top = $('#fix_at_me').offset().top;
      var scrollpos = $(window).scrollTop();
      if (fix_at_me_top <= scrollpos) {
        return 0;
      }
    }
  });
});