Tips for guaranteeing that a Flexslider animation restarts when the previous or next buttons are clicked

I need help with a CSS3/JS issue.

Currently, I am working with FlexSlider and attempting to create an animation as shown in this jsFiddle

You can find the code here: https://jsfiddle.net/v7zvzkp1/

What I'm trying to achieve is an animation that involves text appearing with a bounceInFromLeft effect and then exiting with a bounceOutLeft effect. This should happen for each slide, where the next one also starts with the same animation sequence.

However, when I click on the previous or next buttons of the slider, the animation doesn't restart but rather continues. I'm unsure of what I'm doing wrong. Can someone kindly point out the issue and suggest a solution?

Here's my sample HTML:

<div class="flexslider left">
<ul class="slides">
    <li> 
        <img src="https://coronalabs.com/wp-content/uploads/2013/04/Dilbert_page_img2.png" >
        <div class="meta">
            <h1>Test header</h1>
            <div class="category">
                <p>READ MORE 1</p>
            </div>
            <div class="btn btn-slide btn-animation">MORE </div>
        </div>
    </li>
    <li> 
        <img src="https://www.walldevil.com/wallpapers/w04/thumb/116610-calvin-and-hobbes-calvin-amp-hobbes-comic-strip.jpg" >
        <div class="meta">
            <h1>Test header 2</h1>
            <div class="category">
                <p>READ MORE 1</p>
            </div>
            <div class="btn btn-slide btn-animation">MORE </div>
        </div>
    </li>
    <li>
        <img src="https://i.ytimg.com/vi/XHwMzZqRGZ8/maxresdefault.jpg">
        <div class="meta">
            <h1>Lorem ipsum dolor sit amet, consectetur.</h1>
            <div class="category">
                <p>READ MORE 2</p>
            </div>
            <div class="btn btn-slide btn-animation">MORE2 </div>
        </div>
    </li>
</ul>

Below is the corresponding style:

    img {
    width: 300px;
    max-height: 200px;
}
.flex-direction-nav {
    display: inline-block;
    margin-bottom: 20px;
    width: 100%;
}


.meta h1,
.meta p {
    animation: bounceInLeft 6500ms;
    animation-fill-mode: forwards;
    animation-timing-function: ease-in-out;
    animation-iteration-count: infinite;
    opacity: 0;
}

@keyframes bounceInLeft {
    0% {
        opacity: 0;
        -webkit-transform: translate3d(-3000px, 0, 0);
        transform: translate3d(-3000px, 0, 0);
    }
    30% {
        opacity: 1;
        -webkit-transform: translate3d(25px, 0, 0);
        transform: translate3d(25px, 0, 0);
    }
    40% {
        opacity: 1;
        -webkit-transform: translate3d(50px, 0, 0);
        transform: translate3d(-10px, 0, 0);
    }
    55% {
        opacity: 1;
        -webkit-transform: translate3d(50px, 0, 0);
        transform: translate3d(20px, 0, 0);
    }
    65% {
        opacity: 1;
        -webkit-transform: translate3d(20px, 0, 0);
        transform: translate3d(20px, 0, 0);
    }
    to {
        opacity: 0;
        -webkit-transform: translate3d(-2000px, 0, 0);
        transform: translate3d(-2000px, 0, 0);
    }
} 

As expected, I am initializing the flexslider using jQuery:

$('.flexslider').flexslider({
    animation: "fade",
    controlNav: false
});

Answer №1

Thank you for posing your inquiry

I have devised a rather straightforward solution.

To summarize - simply utilize the "currently active slide" class and apply the animation specifically to it, rather than every p or h1 element on the page.

Please refer to the updated fiddle and test the next/prev buttons.

.slides .toAnimate{
    opacity: 0;
    -webkit-transform: translate3d(-3000px, 0, 0);
    transform: translate3d(-3000px, 0, 0);
}
.flex-active-slide .toAnimate {
  animation: bounceInLeft 6500ms;
  animation-fill-mode: forwards;
  animation-timing-function: ease-in-out;
  animation-iteration-count: 1;
  opacity: 0;
}

Also, ensure to set the initial transform on p and h1 elements (with the added toAnimate class) for cleaner CSS code and to avoid a FOUT.

Lastly, maintain your animation-iteration-count at 1.

I trust this information proves beneficial :)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having difficulty retrieving JSON data from a NodeJS server built with Typescript

My project involves using NodeJS + Express on the back end to send JSON data as a POST response to the front end through JQuery. I'm facing an issue where the message is not reaching the front end, which utilizes a JQuery AJAX call. It's puzzling ...

What can I do to control the behavior of this shake effect?

Looking for a solution to the following coding issue: jQuery.fn.shake = function(intShakes, intDistance, intDuration) { this.each(function() { $(this).css("position","relative"); for (var x=1; x<=intShakes; x++) { $(this).a ...

Having trouble sending an email to multiple recipients using html Mailto?

We are facing an issue with concatenating 400 to 500 emails and putting them in a mailto link. The browser is automatically adding "..." between the emails and clicking the link does not work as expected. <a href='mailto:<a href="/cdn-cgi/l/ema ...

The margin-bottom property does not cause the element to shift or re

Need help with creating a 3-line effect using div and before/after selectors. When applying margin-top in the after selector, the line moves down properly. However, when trying to move the line up using margin-bottom in the before selector, it's not w ...

Error: The function $(...).offset(...) is not defined

I'm encountering an issue that states Error: $(...).offset(...) is not defined. and it's highlighting the $ symbol. I've searched for solutions to this error message, but unfortunately haven't found one yet. Below is my jQuery cod ...

The issue with jquery-ui draggable arises from the failure to access the property 'msie'

Having some difficulty getting jquery-ui draggable to work. I will be sharing my solution with you, and would love to know if this is the best approach? Before diving into my actual work, I decided to test it out. <script src="http://code.jquery.com/j ...

Verify model upon textbox change event

I am currently working with a model class called ActorPhoneModel which has properties such as PhoneTypeTd, PhoneType, and PhoneNumber. The PhoneNumber property is decorated with validation attributes like StringLength and RegularExpression to ensure data i ...

The full width of the Html body in tailwindcss is not being completely utilized

I am new to tailwindcss and encountering a problem. Please take a look at the screenshots provided; the background color is not being applied in the navbar and the HTML body is not displaying full width on medium and small screens. What's perplexing ...

What is the proper way to trigger a nested jQuery function in HTML?

When calling the addtext() function from onclick() in HTML, nested inside the add() function, how can I go about calling the second function? Here's a link with the add() function that displays a textbox and an ADD button invoking the addtext() funct ...

Navigating the techniques of filtering an object with an array

I am looking to filter this object using the aaData array in order to display only unique values. For example, if the first item has the name "testowy2" and the second and third have the name "testowy", I want to show only one instance of "testowy". var j ...

Troubleshooting: jQuery AJAX form submission malfunctioning

Looking to change up the way I submit a form, opting for AJAX over traditional POST submission. The HTML includes a basic form with method="post", and my jQuery script is as follows: jQuery.noConflict(); jQuery(document).ready( function($) { var $form ...

An adaptive image-based menu design that adjusts based on screen size

Although I can get it to function properly, the trouble arises when I attempt to resize it for responsiveness, resulting in a strange scaling issue. Essentially, I want the images to remain at their natural size and align next to each other seamlessly with ...

The jQuery accordion feature fails to function properly in conjunction with ajax requests

While utilizing ajax, I've observed that jQuery effects aren't functioning. This is likely due to the fact that "The new HTML you're adding to the DOM (page) didn't exist when your jQuery ran for the first time." similar question Despi ...

CSS Positioning: the container is not the right size for its content dimensions

Code Snippet: <div content> <div post> <div post> ... </div> Styling: .post { margin: 0; padding: 110px 20px 20px; float: left; width: 560px; position: relative; display: block; } #content { display ...

What is the optimal baseline font size for responsive typography using rem units: percentage or pixels?

Currently, I am exploring the implementation of a responsive typography solution using SCSS and rems. The goal is to utilize media queries solely on the baseline font-size in html rather than on each individual element. After researching different approac ...

Full-Screen Popup Overlayaptic

Is it possible to create a popup that covers the entire browser window, including the search bar and other windows besides just the webpage area, for a very large interactive element? ...

"Hovering over an element triggers a jQuery animation that adds

Everything works perfectly fine. The concept is to create a highlighting effect (such as a background color or underline) that follows you as you hover over the different links in the navigation. It dynamically calculates the left positioning and width, a ...

Use Angular Js to add HTML inner elements to the table

This is my custom HTML code: <body> <div ng-app="tham" ng-controller="tham-control"> <div class="container"> <table class="table table-bordered table-striped"> <thead> ...

Removing a particular value from a cookie using jquery

I'm currently in the process of creating a shopping cart system that allows users to add or remove products from their basket. For each product, I am storing two pieces of information in the product cookie: the product barcode and price. This is wha ...

Determine whether the response from a jQuery AJAX call is in JSON format or binary. If it is found to be binary, proceed

I am currently using ajax to retrieve and download an xlsx file from a PHP script. The script has two possible types of responses: JSON format if there are any warnings preventing the download (such as incorrect parameters), or the xlsx binary stream if ev ...