Web-Design
Monday January 18, 2021 By David Quintanilla
Create Beautiful Scrolling Animations With the CSS Clip-Path Property


In a previous tutorial, we discovered easy methods to create a grayscale-to-color impact on scroll. To implement it, we took benefit of recent front-end options like CSS Grid, the clip-path property, and the Intersection Observer API.

Immediately, we’ll use these instruments and the information gained from that tutorial to construct one other cool scroll impact. As we scroll, web page components will sequentially seem with a slide animation. It is a frequent scroll impact that you just may see on portfolio web sites.

What We’ll be Constructing

With out additional intro, let’s try what we’ll be constructing:

Observe: Remember to learn the aforementioned tutorial as we’ll seize some code snippets from it.

1. Start With the HTML Markup

We’ll begin with a wrapper part aspect that may comprise nested parts. Every sub-section can have one of many following three attainable layouts:

  • A picture on the left, textual content on the precise.
  • Massive textual content on the precise.
  • Textual content on the left, the picture on the precise.

Right here’s a visible illustration of those layouts:

The grid layouts

It’s price noting that for all layouts, we’re going to make use of the identical Pixabay picture. You may do not forget that we’ve already used it in one other scroll tutorial.

The required markup:

2. Outline the Kinds

Developing subsequent, we’ll write down crucial elements of our types. For this demonstration, we received’t focus on the reset guidelines as they aren’t something vital. So, straight to the purpose:

  • We’ll outline the grid, grid-alternate, and big-text courses to seize the totally different layouts. The primary two benefit from CSS Grid, whereas the final one units a most width with margin-left: auto.
  • Simply to observe with a brand new CSS operate, we’ll use clamp() to create fluid typography.
  • Every determine aspect can have a completely positioned ::earlier than pseudo-element. That aspect will act as a picture overlay and be animated first.
  • All animated components will initially be hidden due to the clip-path property. Once more, to actually perceive how this property works, try this tutorial.
  • To chain the animations, we’ll cross applicable values to the transition-delay property of every aspect. Be happy to make them dynamic through the use of CSS variables.
  • On screens as much as 1000px vast, all components will likely be stacked. Moreover, on picture sections, the picture will at all times come earlier than the textual content.

Listed below are the corresponding types based mostly on these assumptions:

3. Animate on Scroll

As we scroll, we’ll animate solely the picture sections (i.e. those who have the grid class). Extra particularly, we’ll animate the next components with this order:

  • The ::earlier than pseudo-element of the determine aspect (the one with the darkish background).
  • The picture.
  • The picture caption.
The sequential animations

When at the very least 50% of every determine aspect enters the viewport, it’ll obtain the is-animated class. In any other case, it’ll lose this class and turn into hidden.

So when the half a part of a determine is throughout the viewport, the related little one components will seem sequentially from totally different instructions. First, the ::earlier than pseudo-element will seem from the precise, then the picture from the left, and at last its caption from the precise.

The JavaScript code that we’re going to want is taken from the grayscale-to-color impact tutorial. We simply must match totally different components:

Listed below are the related CSS guidelines that create the sequence of animations:

Observe: As an alternative of the clip-path property, we may equally have used rework to perform the identical impact. Take a look at the third instance of this tutorial for more information.

Conclusion

That’s it, of us! Immediately we went via a manner for sequentially revealing components on scroll by profiting from superb new front-end instruments. Most significantly, we constructed this impact with out utilizing any libraries.

Hopefully you’ll be capable of enrich your pages with an identical impact.

As a facet word, earlier than deciding to make use of these options on a challenge that requires help for older browsers, test the browser help at caniuse.com.

Right here’s a reminder of what we constructed:

You probably have ever used the clip-path property to construct one thing useful, tell us! As at all times, thanks so much for studying!



Source link