Forum Moderators: open

Message Too Old, No Replies

Scrolling Navigation Panel Forgets Position

Can't get the navigation panel to remember its position

         

ridgedale

9:36 am on Oct 14, 2009 (gmt 0)

10+ Year Member



I have a test site setup at:

<snip>

and I am having trouble trying to resolve an issue relating to the scrolling navigation panel. When the user scrolls down the list and clicks on a link the new page is reloaded but the position in the navigation panel is forgotten and the content jumps to the top. :(

Is there any way to resolve this? Any assistance would be appreciated.

[edited by: eelixduppy at 3:46 am (utc) on Oct. 15, 2009]
[edit reason] no URLs, please [/edit]

ridgedale

10:21 am on Oct 14, 2009 (gmt 0)

10+ Year Member



Apologies, I provided the wrong link. It should be:

<snip>

Thanks in advance.

[edited by: eelixduppy at 3:46 am (utc) on Oct. 15, 2009]
[edit reason] no URLs, please [/edit]

astupidname

3:17 pm on Oct 14, 2009 (gmt 0)

10+ Year Member



Either place the following javascript code inside of your rollover.js file which is linked to each page, or create a new .js file with the following contents and link it to each page. The following script will add an scrTop= (+ a number) variable to the url when one of the links in the sbx_nav div is clicked on (sets an onclick event on each link in the sbx_nav div), and read it from the url when the page loads, to set the initial scrollTop of the sbx_nav div:

function setScroll() {
var div = document.getElementById("sbx_nav");
if (div === null) { return div; }
var m = window.location.search.match(/scrTop=\d+/);
var num = (m === null) ? 0 : m[0].replace(/scrTop=/,'');
div.scrollTop = num;
var links = div.getElementsByTagName("a");
for (var i = 0; i < links.length; i++) {
addListener(links[i], 'click', (function (el,anchor) {
return function () {
var scrTop = 'scrTop=' + el.scrollTop;
anchor.href += (/\?/.test(anchor.href)) ? '&'+scrTop : '?'+scrTop;
return true;
};
})(div,links[i]));
}
};

function addListener(el,evt,func) {
if (el.addEventListener){ //standard
el.addEventListener(evt,func,false); //do not use "on" to prefix the event here
} else if (el.attachEvent){ //IE
el.attachEvent('on'+evt,func);
}
}

addListener(window, 'load', setScroll);

ridgedale

3:46 pm on Oct 14, 2009 (gmt 0)

10+ Year Member



Brilliant! Thanks for your feedback, astupidname. That worked a real treat.

Much appreciated.