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:

[gist id=”aad496470af20910f4009380d94a1bb4″ file=”functions.php” show_line_numbers=”0″]

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.

Here’s an example:

[gist id=”aad496470af20910f4009380d94a1bb4″ file=”markup.html” show_line_numbers=”0″]

Any element that has the data attribute “data-animation”, will be animated by Scroll Reveal. The other data attributes “scale”, “opacity”, and “distance” override Scroll Reveal defaults.

Here’s how you can initialize Scroll Reveal to use data attributes:

https://gist.github.com/devinsays/aad496470af20910f4009380d94a1bb4#file-theme-js

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.

About Devin

I am a developer based in Austin, Texas. I run a little theme shop called DevPress and help manage a WooCommerce shop with Universal Yums. Find me on twitter @devinsays.

3 Responses

  1. 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();

    $(‘[data-animation]’).each( function() {
    console.log( $(this) ); …..

    This is where I have got to and it is not working

    Note: scrollreveal.min.js is being loaded in my footer .

    Am I missing something?

    Kind Regards
    Brad

      1. Brad

        Hi Devin

        Thank you for your reply, clarification and for taking the time to create the example javascript file.

        I will give that a go..

        Kind Regards
        Brad

Leave a Reply to Devin Cancel reply