Using Scroll Reveal for Animation Effects

I’ve been rebuilding a WordPress site that was originally set up using a popular ThemeForest theme and Visual Composer. The theme made it really easy to add animation effects that occur on scroll (as specific elements come into view), but extracting the code for animations wasn’t super easy (it’s part of a 600kb javascript included by theme and mixed with inline styles from Visual Composer).

However, after testing a few different libraries, I found Scroll Reveal worked best as a replacement (3k minified & gzipped).

Basic Set Up

If you want to use Scroll Reveal with default settings, just enqueue it in your theme:

And call then call it on the elements you’d like to animate on scroll.

Customize Animations

The theme I’ve been rebuilding needed unique animations on multiple elements (custom zooms, durations, scaling, delays, etc.), which I didn’t want to set up as individual Scroll Reveal calls. Instead, I decided to use data attributes which could be applied directly in the markup.

Scroll Reveal used to support data attributes by default, but no longer does. So hopefully this helps simplify things if you’re also needing to set up a site with with multiple unique Scroll Reveal animations.

Related

About Devin

I'm a WordPress developer based in Austin, Texas. I run a little theme shop called DevPress and work for a startup called Nano. Find me on twitter @devinsays.

3 Responses

Brad

Hi Devin

Thank you for your article on implementing scroll reveal .

May I please ask for clarity on implementing this in WP

1) I add the wp_enqueue_script
2) add the attributes to the div e.g data-animation=”true”
3) wrap this in a script tag and place in my footer animationsInit: function() {
window.scrollreveal = ScrollReveal();

I think #3 is likely where you’re having trouble. I generally have the animationsInit along with all the other theme javascript in one file. If you’re theme isn’t structured like that, you could enqueue it separately and structure your file like this: https://gist.github.com/devinsays/e8bf6fc0239331e8aaafd3d675a23c5a). In your enqueue call, also make sure to include jquery as a dependency.