PDA

View Full Version : [jQuery] Little help please


jamesaallen
06-27-2008, 06:13 PM
Hello.

This is my first post on this forum, and my first encounter with Javascript.

I am trying to make this website where the nav in the top left is used to select a section and the images below scroll through till they get to this section.

So far i have successfully managed to do this (please excuse the extremely messy site, all the html and css will be changed once i have the javascript working how i want it to). My problem now is trying to get the images to scroll the other way, i can navigate right, but cant navigate back left, instead it moves slightly right still...

The website address is - http://www.jamesaallen.com/test2/issue2.html

I have got a lot of this code from free javascript sort of sites and altered it over a long and tiresome few days. As i have said above, this is my first time doing this and have no idea what i am doing, so i dont even know what some parts of the code mean.

Any help with this little section would be so gratefully recieved:

function scrollToEntry(entry) {
var el = $('e'+entry);
var x = Position.cumulativeOffset(el)[0]-30;
nx = getViewportScrollX();
if (anim) clearInterval(anim);
anim = setInterval(function() {
nx += (nx > x) ? (nx-x)/4 : (x-nx)/4 ;
window.scrollTo(nx,0);
if (nx>x-1) clearInterval(anim);
},20);
return false;
}



getViewportScrollX = function() {
var scrollX = 0;
if( document.documentElement && document.documentElement.scrollLeft ) {
scrollX = document.documentElement.scrollLeft;
}
else if( document.body && document.body.scrollLeft ) {
scrollX = document.body.scrollLeft;
}
else if( window.pageXOffset ) {
scrollX = window.pageXOffset;
}
else if( window.scrollX ) {
scrollX = window.scrollX;
}
return scrollX;
},

getViewportScrollY = function() {
var scrollY = 0;
if( document.documentElement && document.documentElement.scrollTop ) {
scrollY = document.documentElement.scrollTop;
}
else if( document.body && document.body.scrollTop ) {
scrollY = document.body.scrollTop;
}
else if( window.pageYOffset ) {
scrollY = window.pageYOffset;
}
else if( window.scrollY ) {
scrollY = window.scrollY;
}
return scrollY;
}


Best,
James.