Enhancing Your Website with Animation Delay using Animate.css and ViewportChecker

I am attempting to apply a delay to various elements with animated classes on a specific webpage using animate.css version 3.5.1 by Daniel Eden and jquery-viewport-checker version 1.8.7 by Dirk Groenen.

My initial approach was to utilize the setTimeout function like so...

setTimeout(function () {
jQuery('.fadeinleft1').addClass("hidden").viewportChecker({
    classToAdd: 'visible animated fadeInLeft',
    offset: 100
   });
}, 500
);

However, this method affects all elements with the hidden class as well. I am looking to only delay the animation once it enters the viewport, allowing me to customize the delay for each object individually. I have been searching for a solution but have yet to find one.

Answer №1

It's interesting how just when I posed a question, I stumbled upon a solution that only requires some CSS tweaks. There's no need to touch the JavaScript at all. This provides a quick and effortless method for implementing delayed animations while using animate.css and viewport-checker. All you have to do is apply a CSS class that utilizes "animation-delay."

Here's the JavaScript snippet:

jQuery('.fadeinleft').addClass("hidden").viewportChecker({
    classToAdd: 'visible animated fadeInLeft',
    offset: 100
   });

You can create custom animated delay CSS classes as many as you need, which can be applied globally across all animations:

.delay-1 {
animation-delay: .25s;
}
.delay-2 {
animation-delay: .5s;
}
.delay-3 {
animation-delay: .75s;
}
.delay-4 {
animation-delay: 1s;
}

Simply add these classes to your animated elements like this:

<div class="col-md-4 fadeinleft">
    <a href="#">
        <div class="box-border-wht">
                <p>Title 1</p>
                <img src="/images/image1.jpg">
        </div>
    </a>
</div>

<div class="col-md-4 fadeinleft delay-1">
    <a href="#">
        <div class="box-border-wht">
                <p>Title 2</p>
                <img src="/images/image2.jpg">
        </div>
    </a>
</div>

<div class="col-md-4 fadeinleft delay-2">
    <a href="#">
        <div class="box-border-wht">
                <p>Title 3</p>
                <img src="/images/image3.jpg">
        </div>
    </a>
</div>

That's all there is to it!

Answer №2

It seems unnecessary to use viewportChecker() or any JavaScript/jQuery on this occasion. The jQuery code in your solution, adding the hidden CSS class to the element (hidden has been replaced by d-none in Bootstrap 4), is redundant since the animated class handles this automatically. Animate.css aims to offer smooth animations without excessive JavaScript/jQuery code.

Since Animate.css relies on the animation(-name) property for animations, it naturally respects the animation-delay property as well. Removing the jQuery code altogether should not affect the functionality of your solution (as mentioned earlier).

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

Guide to inserting text into an html element upon clicking an ASP:Button

In my code, there is a DIV that holds some text. Accompanying the text is an asp:Button. When this button is clicked, I aim to access and save this particular text. Nonetheless, it seems that once the button is clicked, the content of the DIV resets - lik ...

When utilizing AJAX, certain web pages may contain a querystring

Encountering an issue with ajax when using query strings. Data can be successfully sent when the page does not have any query string and Info.aspx/Save works perfectly fine. However, when I include query strings and post the same data, it results in a HTTP ...

Troubleshooting Div Element Width in CSS Not Functioning

When working on a form design, I encountered an issue where the text labels were not aligning to the same width. Despite setting the width, it didn't seem to work as expected: .form-label { display:inline; width: 160px; } <div class="form-label ...

Setting the modal option to false in a Messi pop-up dialog box

After attempting to close the Messi pop-up with "$('.messi').remove();" I encountered an issue where the modal set in the pop-up persisted even after its removal, hindering any changes to the web page. Is there a manual way to set modal:false? ...

Tips for sharing a React component with CSS modules that is compatible with both ES Modules and CommonJs for CSS modules integration

Some frameworks, like Gatsby version 3 and above, import CSS modules as ES modules by default: import { class1, class2 } from 'styles.modules.css' // or import * as styles from 'styles.modules.css' However, other projects, such as Crea ...

Using a PHP variable to trigger the jQuery .show() function

I'm attempting to trigger jQuery .show() events based on PHP variables. Below is my PHP code (retrieved from a form submission on another page): $last_pic_displayed = trim($_POST["last_pic_displayed"]); if (strlen($last_pic_displayed) <= ...

Every time I attempt to input text into the text area, the page automatically refreshes, preventing me from completing any entries

Currently, I am working on developing a webpage that can dynamically update text inputted by users in a database. However, I have encountered an issue where the page refreshes automatically whenever I click on the textarea. If I type quickly enough, some o ...

Are the navigation links at the bottom of the sidebar?

I've been experimenting with positioning three navigation links at the bottom of a sidebar I created, but I'm having trouble getting them there. Despite my attempts, I can't seem to figure out how to make it work. The background of the nav ...

Obtaining a distinct identifier from an element

Struggled with this one, I've read several articles but nothing is clicking for me. Any assistance would be greatly appreciated. I'm trying to achieve a specific action on click of 'slick-toggle', where only the corresponding 'sli ...

What is the counterpart of Ajax.updater in Jquery?

Could you please advise on how to achieve the same functionality as the prototype code below but using Jquery? var myAjax = new Ajax.Updater('abc', '/billing/add_bill_detail', { method: 'get', parameters: pars, ...

Using Jquery to make an Ajax request to an Asp.net Web Method

My current approach involves using a jquery method to transmit only the member identification # from the client side to the server side. On the server side, I have a traditional Web Method in place to receive the data and execute SQL queries accordingly. ...

Enlarging the current division while reducing the size of the others when hovering

Currently, I am working on a school project that involves creating a slideshow on a webpage. However, I have reached a point where I am unsure of how to proceed. Here is the progress I have made so far: body { background-color: #252525; } #wrapper { ...

How to efficiently use nested $.each() in DataTables with jQuery

After receiving Json data from the server, I utilize DataTables to display the information accordingly. The json contains multidimensional arrays with rows consisting of columns that may have more than one value. Here's an excerpt: { "info_table ...

Struggling to make jeditbale ajax call function properly

Currently, I am attempting to modify text directly on the webpage using the jeditable plugin. Unfortunately, I have encountered a challenge when it comes to saving the updated data properly through an ajax call. Although I can successfully edit the text, i ...

Using arrays to create visual Google charts

I am attempting to pass an array of numbers to a Google chart by extracting the array from a div with the class .likescount. var i, $mvar = $('.likescount'); function logit( string ) { var text = document.createTextNode( string ); $(&a ...

The element within the flexbox does not extend across the entire width, despite being designated as 100% full width

I'm currently attempting to center certain elements to ensure they are visually aligned. The upper div seems to have some odd space on the right, causing all the content within that div to be shifted and not accurately centered. On the other hand, th ...

Angular and Datepair seem to have trouble cooperating

I've been struggling to solve this issue for a few days now and I feel like it's time to seek help from you wonderful people. I am currently developing a calendar application using Angular along with the datepair/datepicker/timepicker libraries. ...

What steps should I take to transform this into an ajax form?

I'm struggling with converting this code into an Ajax form. Can someone guide me on the process? @using (Html.BeginForm("", "CollaborativeProjects", FormMethod.Post, new {enctype="multipart/form-data"})) { <input type="file" name="FileUpload1 ...

Checking for null variables in returned data using AJAX in Laravel 7

Currently in the process of developing a Laravel 7 project, I have encountered an issue with mapping returned data from my controller to a modal. Specifically, I am looking to validate if a certain value is null below the 'Appointment' section wi ...

Is there a way to identify modifications in the DOM using jQuery UI Sortable?

My website is built using nodejs express and mongodb, and I am interested in integrating this library. I am curious about how I can detect changes in the order of elements to save their state. Should I use a form submission or jQuery functions? For exampl ...