Fade in Animations combined with delay not working properly => Switch to Intersection Observer API for scroll triggered animations

Created on 21 March 2023, over 1 year ago
Updated 7 March 2024, 10 months ago

Problem/Motivation

Steps to reproduce

Set the fadeInLeft entrance animation on a paragraph, also set a delay of 1000ms.
Result:

  1. The .in-scope class is added => opacity goes to 1, so the paragraph is getting visible for a moment
  2. The animation fires (paragraph hides again, and then fades in)

Proposed resolution

The problem comes from a combination of a CSS hotfix, located in our theme and a problem with Animate.css + the DROWL Paragraphs script to handle the animations.
To make all "fading entrance" animations work, we needed to set an opacity:0; to them. Otherwise, those Paragraphs would be directly visible, till the animation fires (hide => fadein).

.has-animation[data-animations*="\"animation\":\"fade"]:not(.in-scope){
  opacity:0;
}

Without a delay, we have no problem, when the .in-scope class is added, our hotfix "disappear" (opacity:1) and the animation fires right in that moment, so opacity is getting 0 again .. then it fades in.

We should refactor this animation thing.. the settings are fine, but the script uses outdated techniques (switch to Intersection Observer) and we should address the fadeIn problem right in this module.

Maybe we only need to set the .in-scope class with the Intersection Observer (+ the hover animations option thing..) and add some CSS like:

.paragraph.has-animation:not(.in-scope){
  animation-name: none !imporatnt;
}

This should fire the animation, once the .in-scope class is removed.

In addition, we need the animation delay as CSS variable on the paragraph wrapper, so we can simply add:

.paragraph.has-animation{
  animation-delay: var(--paragraph-animation-delay, 0ms) !important;
}

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024