Scroll to same place on page

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.

  1. // to handle the front page Get Started button
  2. //// Contructor
  3. function webpage(name,location){
  4. this.name = name;
  5. this.location = location;
  6. }

  7. var welcome = new webpage("welcome",0);
  8. var about = new webpage("about",0);
  9. var portfolio1 = new webpage("portfolio1",0);
  10. var portfolio2 = new webpage("portfolio2",0);
  11. var portfolio3 = new webpage("portfolio3",0);
  12. var portfolio4 = new webpage("portfolio4",0);

  13. var currentLoc = new webpage(); // the holder of information

  14. function gotoLocation(location){ // chain of events
  15. if (currentLoc.name != null){ // if this isn't the first link click
  16. eval(currentLoc.name).location = $('body').scrollTop(); // record the current location of the scroll bar with the old page name
  17. }
  18. $('#myTab a[href="#' + location + '"]').tab('show'); // change the page
  19. currentLoc.name = eval(location).name; // record the new page name
  20. if (eval(currentLoc.name).location != 0){ // if you've visted this page before
  21. $('body').scrollTop(eval(currentLoc.name).location); // scroll to where the page last was
  22. } else {
  23. $('body').scrollTop(0); // scroll to where the page last was
  24. }
  25. };
thanks a lot for the help!


Matt