Scroll to same place on page
www.madebymatt.com is my site.
this is the main code for the tabs at the top. using google bootstrap tabs, I have all the various pages on my site as tabs within one actual page.
I wanted to keep track of where the user was last on each tab.
it is working, but isn't working. it keeps track of where the user was on the tab, but when it goes to scroll to that location, it doesn't scroll all the way if the page before it was shorter in length. so if you're transitioning from a long page to a shorter page, it works perfectly and goes back to the original location. But if you're transitioning from a short page to a longer page, it only scrolls down as far as the previous page can scroll down.
timing-wise, it seems right, but because of the issue above, I'm not sure. Is this the best way to do this?
this is tabs.js on the server.
- // to handle the front page Get Started button
- //// Contructor
- function webpage(name,location){
- this.name = name;
- this.location = location;
- }
- var welcome = new webpage("welcome",0);
- var about = new webpage("about",0);
- var portfolio1 = new webpage("portfolio1",0);
- var portfolio2 = new webpage("portfolio2",0);
- var portfolio3 = new webpage("portfolio3",0);
- var portfolio4 = new webpage("portfolio4",0);
- var currentLoc = new webpage(); // the holder of information
- function gotoLocation(location){ // chain of events
- if (currentLoc.name != null){ // if this isn't the first link click
- eval(currentLoc.name).location = $('body').scrollTop(); // record the current location of the scroll bar with the old page name
- }
- $('#myTab a[href="#' + location + '"]').tab('show'); // change the page
- currentLoc.name = eval(location).name; // record the new page name
- if (eval(currentLoc.name).location != 0){ // if you've visted this page before
- $('body').scrollTop(eval(currentLoc.name).location); // scroll to where the page last was
- } else {
- $('body').scrollTop(0); // scroll to where the page last was
- }
- };
thanks a lot for the help!
Matt