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 trial

JavaScript

How do I make the window scroll to a certain point?

As inspiration, I use this website: http://www.bulldoggin.com/home/

As you can see, there's no way to just scroll, each time you scroll it automatically jumps to a certain point in the document. There's no way to go "halfway".

Is there a way to solve this using javascript, jQuery or anything? I don't want to use buttons to jump to a certain point of the page, but I want to achieve this by scrolling.

Any ideas?

PLUS: How do I make an animation start/stop, as soon as it comes into view? Just like they did it on the link I posted?

1 Answer

That type of effect can be done using JavaScript and jQuery. It will take a bit of coding and figuring out, I have three links that should help point you in the right direction.

jQuery Scroll function : https://api.jquery.com/scroll/

Get Scroll Direction: http://stackoverflow.com/questions/4326845/how-can-i-determine-the-direction-of-a-jquery-scroll-event

Scroll to point: http://stackoverflow.com/questions/1586341/how-can-i-scroll-to-a-specific-location-on-the-page-using-jquery

A basic layout of your code would be: On scroll -> check direction -> scroll to next/prev point on page (this will be where animating takes place)

OR use a jQuery plugin: https://projects.lukehaas.me/scrollify/

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Converted your comment to an answer so that the question can be seen as having an answer and also be upvoted/chosen for Best Answer :smiley:

Thank you, that helped me a lot! I got stuck on this for quite a while, but it works perfectly now :)