开发者

MooTools onLoad SmoothScrolling (Lim Chee Aun Method)

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


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

Example

Full Code


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜