views:

73

answers:

2

Hi ppl,

so, the thing is :

when someone clicks on a link to my website and page loads, prototypeJS is supposed to observe if there is a #elementId in the URL and stop browser from jumping to the element and do it with scrollTo().

I've seen this before but only with jQuery, but couldn't figure out how to do it with prototypeJS.

A: 

To stop the jump in your click event handler just have return false; at the end. Jump solved.

You should have been scrolling during this time.

What have you tried to do this assignment?

James Black
that's not the problem at all, i can create observers for all anchors with # in href and replace the onclick event with scrolling to element. I think Tobie Langel wrote a blog post on that particular topic few years ago, pretty easy to achieve.What I'm trying to get is 'dom:loaded' observer to stop browser from scrolling to element, like if u clickhttp://stackoverflow.com/questions/1654389/replace-default-browser-jumping-to-elementid-with-effect-scrollto#answer-1654643, it isn't supposed to throw you right at your answer but cancel that browser event and use scrollTo() on it.
Kemo
and that's with opening that link in new tab / window, not in this one. =)
Kemo
How do you scroll to a new window? Javascript doesn't work well between separate windows, and even changing tabs would be a neat trick.
James Black
A: 

You can get rid of anchors (<a href=".." name="elementId">), so if you refer to not existing one then you page scroll gonna be just 0. You add onload listener, check if you have "#..." in url once DOM is loaded, if you do and id is valid then $('elementId').scrollTo();

Sergii