Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

General Discussion

Alejandro Hernandez
Alejandro Hernandez
7,629 Points

Scroll 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
STAFF
Jim Hoskins
Treehouse Guest Teacher

Hi 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
Alejandro Hernandez
7,629 Points

I 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
STAFF
Jim Hoskins
Treehouse Guest Teacher

I 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
Alejandro Hernandez
7,629 Points

Oooooh I see. Thanks for the resources and the quick response.

Alejandro Hernandez
Alejandro Hernandez
7,629 Points

Holy Smokes?! Didn't know there was a blog with resources. Thanks Again.