Repeated animations on a Slick carousel

Created on 12 July 2024, 6 months ago

Problem/Motivation

I am using Slick Paragraphs to carousel a paragraph that has an image field, a caption field and a second text field. Since I am not able to add classes to an image during upload I added the class in the paragraph template like <div class="wow animate__animated animate__slideInLeft">{{ content.field_image }}</div>. Then for the caption and other text field I added the classes per item in CKEditor like

<p class="wow animate__animated animate__flipInX animate__delay-2s">
    SLIDE TITLE
</p>

.

Now when the page loads the animation for the image will play and so for the caption and the other text. But they only all play once. Once the carousel rolls, no more animations appear on the slide even the ones I added to the captions of the next slides. I tried to use repeat and delay classes without luck. The carousel itself has a delay of 6s so I tried to delay the animation on the caption of the next slide like

<p class="wow animate__animated animate__flipInX animate__delay-8s">
    SLIDE TITLE
</p>

without any luck.

Is there a way to write the classes such that when a slide loads the image is animated again and the captions re-animated for each slide that loads?

Note that Slick Paragraph carousels paragraphs 'as is' so animations will have to target the paragraph template IMO, I don't really know.

Thank you.

💬 Support request
Status

Active

Version

1.1

Component

Documentation

Created by

🇳🇬Nigeria chike Nigeria

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

Comments & Activities

  • Issue created by @chike
  • 🇵🇱Poland mahyarss

    Given that the WOW.js library is a Scroll Reveal library, it means that animations are triggered when the element comes into the viewport as you scroll. However, when using a carousel like Slick, all the paragraphs in the slides are in the same horizontal position. Therefore, they all get animated simultaneously as they are in the same scroll position. Using `delay` and `repeat` might not provide a fundamental solution. Instead, it might be better to handle this with a custom JavaScript code that integrates the animations with Slick's events, something like the code below:

    (function ($, Drupal) {
      Drupal.behaviors.animateCarousel = {
        attach: function (context, settings) {
          $('.your-carousel-class', context).once('animateCarousel').each(function () {
            var $carousel = $(this);
    
            $carousel.on('afterChange', function(event, slick, currentSlide) {
              // Remove previous animation classes
              $('.slick-slide', $carousel).find('.wow').removeClass('animate__animated animate__slideInLeft animate__flipInX');
    
              // Add animation classes to the current slide
              $(slick.$slides[currentSlide]).find('.wow').addClass('animate__animated animate__slideInLeft');
    
              // Add animation classes to the text elements
              $(slick.$slides[currentSlide]).find('p').addClass('animate__animated animate__flipInX');
            });
    
            // Initialize the carousel
            $carousel.slick({
              // Add your carousel settings here
            });
          });
        }
      };
    })(jQuery, Drupal);

    This quick solution is what came to my mind for your request. Of course, there might be other and possibly better ways to achieve this, but I wanted to suggest the fastest way to address your issue first.

    I hope this helps you. Please let me know if you have any further questions or need additional assistance. please feel free to report back here.

  • 🇳🇬Nigeria chike Nigeria

    This is Drupal 10.3.1 and I could not get past Uncaught TypeError: $(...).once is not a function. When I managed to get past it I can't tell why the code is not working either the changes I made or the code itself. I guess .slick--field-slider should be okay for .your-carousel-class?

    I can remove all the animation classes I added on the carousel so this code can add the classes afresh without having to remove and append to existing classes.

    Thank you.

Production build 0.71.5 2024