/* Script: SmoothScroll.js Class for creating a smooth scrolling effect to all internal links on the page. License: MIT-style license. */ var SmoothScroll = new Class({ Extends: Fx.Scroll, initialize: function(options, context){ context = context || document; var doc = context.getDocument(), win = context.getWindow(); this.parent(doc, options); this.links = (this.options.links) ? $$(this.options.links) : $$(doc.links); var location = win.location.href.match(/^[^#]*/)[0] + '#'; this.links.each(function(link){ if (link.href.indexOf(location) != 0) return; var anchor = link.href.substr(location.length); if (anchor && $(anchor)) this.useLink(link, anchor); }, this); // if (!Browser.Engine.webkit419) this.addEvent('complete', function(){ // win.location.hash = this.anchor; // }, true); }, useLink: function(link, anchor){ link.addEvent('click', function(event){ this.anchor = anchor; this.toElement(anchor); event.stop(); }.bind(this)); } });