Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAlejandro Hernandez
7,629 PointsScroll Position on Refresh, How does TeamTreehouse do it?
Working on a personal project and I was wondering how Team treehouse maintains exact page scroll position on page refresh/reload?
5 Answers
Jim Hoskins
Treehouse Guest TeacherHi Alejandro!
I'll look around, but I don't believe we are doing anything special. Most browsers will attempt to scroll to the previous region of the page if you reload or hit the back button.
Some things could interfere with it: like JavaScript that messes with the scroll, anchor links (the #part of the url), or loading the content in dynamically.
Are you experiencing behavior where it is not restoring the scroll state?
Jim
Alejandro Hernandez
7,629 PointsI was taking a team treehouse ruby quiz on my iphone and noticed when I selected an answer + submitted an answer my iphone browser maintained my exact position when the next quiz question began.
This was awesome.
I'm not report a technical issue, I was just wondering how Team Treehouse executed it so I can learn and use it on a personal project.
Jim Hoskins
Treehouse Guest TeacherI think I understand your question better now.
On quizzes, we don't actually load a new page between each question, which would of course cause the page to be scrolled to the top.
Instead we use JavaScript and Ajax to change the content of the page to the new question. Since it's the same page, the scroll doesn't change.
You can read an introduction to Ajax here: http://blog.teamtreehouse.com/a-quick-guide-to-understanding-ajax
An upcoming stage of our ruby on rails social network will be utilizing Ajax
Hope that helps!
Alejandro Hernandez
7,629 PointsOooooh I see. Thanks for the resources and the quick response.
Alejandro Hernandez
7,629 PointsHoly Smokes?! Didn't know there was a blog with resources. Thanks Again.