Smooth anchor scrolling using prototype and scriptaculous unobtrusive with href attribute


/ Published in: JavaScript
Save to your folder(s)

use an anchor like this: <a class="scroll_me" href="#main">...
scriptaculous needed ;)


Copy this code and paste it in your HTML
  1. document.observe("dom:loaded", function() {
  2. if ($$('a.scroll_me')) {
  3. $$('a.scroll_me').invoke('observe','click', function(event) {
  4. Event.stop(event);
  5. var elementLink = Event.element(event).readAttribute('href');
  6. var scrollHere = elementLink.substr(1, elementLink.length);
  7. Effect.ScrollTo(scrollHere);
  8. return false;
  9. });
  10. }
  11. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.