Posted By

shapeshifta on 12/29/09


Tagged

prototype Scriptaculous unubtrusive


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

Milad
cfleschhut
francotalarico


Smooth anchor scrolling using prototype and scriptaculous unobtrusive with href attribute


 / Published in: JavaScript
 

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

  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
Posted By: shapeshifta on January 5, 2010

erm, somehow my link got destroyed -.- use something like ...

Posted By: shapeshifta on January 5, 2010

grrr <a class="scroll_me" href="#main">...

You need to login to post a comment.