jQuery Waypoints

http://imakewebthings.github.com/jquery-waypoints/

Hey campers, I've seen posts asking for something along these lines in the past, so hopefully it's useful to somebody out there.

I've pushed a little jQuery plugin that makes it quick and easy to do something when you scroll to an element, like this:

$('#someElement').waypoint(function() {
   console.log('Hello world');
});
Raw

That would run when #someElement hits the top of the browser window. There are a number of options and such to change the behavior, but you can check it all out in the documentation section. Here's a more full blown example:

$('#someElement').waypoint(function(event, direction) {
   var targetOpacity = direction === "down" ? 1 : .25;
   $(this).stop().animate({ "opacity": targetOpacity });
}, {
   offset: '50%' // When the element reaches the middle of the browser
});
Raw

This would fade #someElement in to full opacity when it reaches the middle of the browser window, and fade it out to .25 opacity when scrolling up back through the same spot.

Feedback, questions, requests are always welcome.

Tagged: javascript jquery plugin scrolling
Comments are only visible to Forrst members. Log in or Request an invite.
3 new notifications