views:

159

answers:

2

From the post Lim Chee Un made here: http://davidwalsh.name/mootools-onload-smoothscroll

window.addEvent(‘domready’, function() {
new SmoothScroll({ duration:700 }, window);
var el = window.location.hash.substring(1); // the hash
if(el) {
window.scrollTo(0,0);
var scroll = new Fx.Scroll(window, { wait: false, duration: 700, transition: Fx.Transitions.Quad.easeInOut });
scroll.toElement(el);
}
});

I would like to have the page automatically smooth scroll to the # in the URL when the page loads.

Smooth scrolling works when the link is like this, ie same page:

<a href="#pageHeading">Books & Booklets</a>

Rather than how I need it like this:

<a href="books.html#pageHeading">Books & Booklets</a>

Can anybody shed some light on why this isn't working?

Thanks

A: 

Did you place the same javascript also in "books.html" page?

If not you need to place your script in there and in every page you want the smooth scroll to happen on page load.

Marco Demajo
Yes I did place the javascript on all the pages....
Anthony
+1  A: 

Lim Chee Aun was kind enough to post up a solution!

Example

Full Code

Anthony