Sequence of animation transitions in and out

I searched for a solution to my problem and attempted to resolve it using CSS3 animation or setInterval, but unfortunately saw no results.

MY GOAL:

I aim to create an animated loader loop with a fading in and out logo rotating clockwise indefinitely.

Why does setInterval not work? It doesn't work because each animation has its own delay, and the repeat delay is not applied.

function runIt() {
    var time = 600;
    $(".first").fadeIn(time).fadeOut(time);
    $(".second").delay(time).fadeIn(time).fadeOut(time);
    $(".third").delay(time*2).fadeIn(time).fadeOut(time);
    $(".fourth").delay(time*3).fadeIn(time).fadeOut(time);
   };
runIt();

SEE EXAMPLE ON CODEPEN

Any help would be greatly appreciated! :)

SOLUTION FOR THOSE FACING THE SAME ISSUE:

            function runIt() {
                var time = 600;
                $(".first").fadeIn(time).fadeOut(time, function(){
                    $(".second").fadeIn(time).fadeOut(time, function(){
                        $(".third").fadeIn(time).fadeOut(time, function(){
                            $(".fourth").fadeIn(time).fadeOut(time, runIt); 
                        });
                    });
                });



            };
            runIt();

Answer №1

One way to approach this is by utilizing the setInterval method, although a more organized approach would involve triggering the runIt function once again from the callback of the last animation:

function runIt() {
    var time = 600;
    $(".first").fadeIn(time).fadeOut(time);
    $(".second").delay(time).fadeIn(time).fadeOut(time);
    $(".third").delay(time*2).fadeIn(time).fadeOut(time);
    $(".fourth").delay(time*3).fadeIn(time).fadeOut(time, runIt); // restart runIt after fadeOut completes
};
runIt();

Answer №2

Using SetInterval is effective. Make sure to execute the function prior to setting the interval:

begin();

setInterval(function() {
  begin();
}, 3600);

Try out this CodePen demo here.

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

Disable the scroll animation feature for certain IDs

I implemented JavaScript code to animate scrolling for each block with a specific ID. However, when I added Bootstrap's tabs, the animation interfered with the functionality of the tabs. Is there a way to disable the scroll animation specifically for ...

Issues with the animation of the navbar menu button are preventing it from functioning

I have been attempting to incorporate animation when the navbar-button is toggled on smaller screen sizes. Inspired by the design of .navbar-toggle.larr in this particular template, I tried to implement a similar effect. /* ANIMATED LEFT ARROW */ .navbar- ...

Ensuring that the second level unordered list is set to a height of 100% of the first unordered list, rather than the

I'm working with this menu http://codepen.io/alexandernst/pen/oxpGYQ (I wanted to include it here but the result viewer on SO is causing some display issues...) and I am trying to ensure that the second and third level ul elements are the same height ...

What is the method to adjust the width of a Google Recaptcha?

I have been working on implementing Google reCAPTCHA v1 into an ASPX project using a DLL for that purpose. I have also set up a control validator for all fields in my form. While my website is responsive, I am having trouble adjusting the width of the Goo ...

Personalized color palette for CSS styling

Is there a way to implement a color scheme selection feature on my HTML site using CSS? I currently have base.css, green.css, and orange.css files. By default, the site loads with the green color scheme. How can I allow users to switch to the orange color ...

Defining colors in TinyCSS and GTK themes using the `@define-color

I've been working on a project that involves parsing GTK+3 themes using the TinyCSS library. However, it seems that TinyCSS is not recognizing lines such as @define-color base_color #FAFAFA; These definitions are stored in parser.styleSheets[0].er ...

Transferring Object Information from AJAX to PHP

When attempting to send data to a PHP file for database storage, I am not receiving any response. If a checkbox is checked, the [obj][idCheckbox] value is set to 1; otherwise, it is set to 0. This is the file responsible for sending the data: var i=0; v ...

Is the HTML5 type of button functioning properly, while the type of submit is not working as

Looking to validate a form before running a JavaScript function? Check out this code snippet: function updateMap() { //dummy } <form> <div class="group"> <input type="number" id="hour" min="0" max="23" required> <span cl ...

Is there a reason the hr tag elements aren't extending to the full width within the list?

I am having trouble with my hr tag elements in the table I created - they are not spanning the full width like the line above them. I have tried adjusting the width property but it doesn't seem to be working. Can anyone offer advice or guidance on how ...

What is the best way to ensure input text fills the entire grid?

Take a look at this code snippet: <div class="form-group col-md-6"> <label class="col-md-4">Last Updated (Real Time)</label> <input class="form-control col-md-8" type="text" ng-model="status.lastUpdated" ng-readonly="true"/ ...

Unexpected JSONP Parsing Issue Despite Correct JSON Data

I've implemented a Cross Domain AJAX request using JSONP, and it's working fine with CORS. However, I'm facing an issue with JSONP. I've checked other threads but couldn't find a solution for my case. Below is the code snippet: ...

Creating a dynamic scrollTop feature using a Jquery button in HTML

Recently, I created a website using WordPress and encountered an issue with implementing a scrolling arrow on the page. The current setup only allows the arrow to scroll down once, whereas I need it to navigate through the entire page smoothly. Here is t ...

What is the best way to ensure a div spans the entire width of the screen?

I came across a helpful post on extending my container to the edge of the screen. Despite following the instructions, I still noticed a white space (highlighted in red): https://i.sstatic.net/w0bGf.png To address this issue, I experimented with setting t ...

Slide in the Toggle Effect to Your Navigation Menu

Seeking help with enhancing my jQuery dropdown menu to include a slide down toggle effect similar to this example: http://jsfiddle.net/LaSsr/188/. Any assistance in applying this slide effect to the following JSfiddle would be greatly appreciated. Thank yo ...

Loading User Interface Control Dynamically with AJAX and C#

I'm currently working on a project where I need to dynamically load a PlaceHolder with a *.ascx page using an AJAX call. However, I've encountered an issue related to its static nature. The problem arises because I am unable to access the PlaceH ...

Support with formatting a dynamic asp:CheckBoxList utilizing Bootstrap styling

I'm currently facing a challenge with styling my asp:CheckBoxList that is populated with values from a database. My framework of choice is Bootstrap 4.3.1 and I'm attempting to style the CheckBoxList using the default example below: <div cla ...

An improved method for populating object values with checkboxes

Apologies for the vague question, but finding a suitable title was tricky. This is my jQuery code: const selectionInfo = {}; const housenrChecked = $("#housenr_export")[0].checked; selectionInfo.housenr = housenrChecked ? 1 : 0; const phoneChecked= $(" ...

What could be the reason for Vue model not updating with input.val(value) changes?

I've created an editable table: <div id="myTable"> <b-table class="overflow-auto" :items="filtered" :fields="visibleFields" :filter="filter"> <template v-for="field in ed ...

.ajax() triggers a page refresh upon pressing the ENTER key

Utilizing Ajax to update the database with a new folder leads to page refresh when hitting ENTER. On the form, I have onkeypress="if(event.keyCode==13) savefolder();". Below is the Javascript code where pressing enter calls savefolder function that sen ...

Mapping form fields to database objects is an essential step in ensuring seamless data integration

I am curious about the process of building edit forms using modern frameworks such as express with mongo db. To elaborate on my question, I aim to create an application that allows users to edit certain fields of objects stored in Mongo. Each time a form ...