Auto scrolling page navigation with $$

Written by on March 13th, 2007 in Ajax News.

Tobie Langel likes a fistful of dollars and uses them to explain how to use auto scrolling page navigation with the new $$ operator in Prototype 1.5.1 RC.

The article takes the initial:

HTML:

  1.  
  2. <a href=”#about” onclick=”new Effect.ScrollTo(’about’,{offset:-140}); return false”>About</a>
  3.  

and gets it down to the unobtrusive:

HTML:

  1.  
  2. <a href=”#about”>About</a>
  3.  

and the nice new support for CSS 3:

JAVASCRIPT:

  1.  
  2. Event.observe(window, ‘load’, function() {
  3.   $$(’a[href^=#]:not([href=#])’).each(function(element) {
  4.     element.observe(’click’, function(event) {
  5.       new Effect.ScrollTo(this.hash.substr(1));
  6.       Event.stop(event);
  7.     }.bindAsEventListener(element))
  8.   })
  9. })
  10.  

Check out the auto-scrolling demo to see it in action.

Source: Ajaxian
Original Article: http://ajaxian.com/archives/auto-scrolling-page-navigation-with

Leave a Reply

You must be logged in to post a comment.



Site Navigation