Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking CSS3 Animations/Transforms with Scroll Event

I am looking for a way to link CSS3 transitions to a scroll event. I'm looking for similar functionality to http://nizoapp.com/, where certain elements would move when you get to a certain scroll point on the page. I know you would have to call the scroll event with jQuery (using offset and scroll), but I am curious if there is a way to then use CSS3 for the animation portion or if that needs to be done in jQuery. Either way, I'd love some help on how to get a jump start on getting this to work. Thanks for the help.

like image 247
Andrew Avatar asked Nov 17 '11 14:11

Andrew


People also ask

How do I trigger a CSS animation without scrolling JavaScript?

Can I trigger CSS animations on scroll without Javascript? The short answer is NO. Window scrolling is an event and CSS itself is not capable of detecting event changes as of now. So we must use javascript to measure the scroll and trigger something to which CSS can react.

How do you trigger an event on scroll?

The scroll() method is used to trigger the scroll event or attach a function to run when scrolling occurs. The scroll event occurs when a scrollbar is used for an element. The event is triggered when the user moves the scrollbar up or down. We can use the CSS overflow property for creating a scrollbar.


2 Answers

A good starting point could be the jQuery Waypoints plugin. It makes it easy to execute a function whenever you scroll to an element, and can also apply classes based on what's currently in view. You could then use those to trigger the CSS animations that you're after.

UPDATE - I've just come across the Scrollorama jQuery plugin. The author does state that it's not been thoroughly tested, but it's designed to do precisely what you are after, and definitely looks like a good starting point.

like image 146
CherryFlavourPez Avatar answered Nov 09 '22 07:11

CherryFlavourPez


There is no way link a specific CSS to a scroll position. You will need to include some javascript glue to achieve that effect. My favorite method is to bind to the window onscroll event and put your animation code there.

like image 37
Cesar Canassa Avatar answered Nov 09 '22 08:11

Cesar Canassa