imakewebthings / waypoints

Waypoints is a library that makes it easy to execute a function whenever you scroll to an element.
http://imakewebthings.com/waypoints/
10.38k stars 1.34k forks source link

Allow for sticking at the bottom too. #385

Closed zoffixznet closed 9 years ago

zoffixznet commented 9 years ago

It would be nice if the Sticky shortcut had an option to stick to the bottom of the screen. Essentially, functioning the same way the normal sticky would, if you'd turned the screen upside down.

I have an element that normally sits atop the footer. On page load, I wanted to "stick" that element to the bottom of the window, even if the footer is a few screenfulls below the fold.

When the user scrolls down, this element would unstick itself, once the footer is reached.

In fact, that's what I thought direction option was far (but no).

Perhaps, there's an easier way, but the way I solved it took some tinkering and the code isn't intuitive because it's basically doing things in reverse.

Here's a demo: http://zoffix.com/new/del/WayPoints-Issue-Sample/WayPoint-Sample.html The red bar is the stickie, and black portion is the footer.

imakewebthings commented 9 years ago

@zoffixznet That is, indeed, what the direction parameter is for:

new Waypoint.Sticky({
  element: foo,
  direction: 'up',
  offset: 'bottom-in-view'
});

Does this help?

zoffixznet commented 9 years ago

Yes, indeed that produces the desired results :)

Sorry, I should've read the docs more carefuly :) Thanks.