Transitionend event fails to trigger when Chrome tab is not in focus

$("#element").addClass("myclass").on('webkitAnimationEnd oanimationend msAnimationEnd animationend',
function (e) {
  $("#element").addClass('text-success');
  $("#element2").addClass('myclass2');

  setTimeout(function () {
    $("#element").fadeOut("slow", function () {
      $("#element").remove();
    }); 
  }, 60000);
}); 

This code functions correctly when the tab is active. However, if the tab becomes inactive, the code will pause at the 'on' event.

Does anyone have any suggestions on how to make this code work even if the tab is inactive, so that when switching back to the tab everything appears as it should?

Answer №1

To ensure your code runs smoothly even when the tab is inactive, consider using javascript for animations instead of css. This will help maintain continuous animation playback regardless of tab activity.

The behavior of inactive tabs varies depending on the browser being used.

Answer №2

Although I'm unsure about how to determine if the animation has finished when the tab is not in focus, you can manually trigger the event after a certain delay if you have an estimate of how long the animation should last. For example:

var executed = false;

$("#element").addClass("myclass").on('webkitAnimationEnd oanimationend msAnimationEnd animationend',
function () {
  execute();
});

setTimeout(function () {
  execute();
}, 10000); // Delay for triggering

function execute() {
  if(!executed) {
    $("#element").addClass('text-success');
    $("#element2").addClass('myclass2');

    setTimeout(function () {
      $("#element").fadeOut("slow", function () {
        $("#element").remove();
      }); 
    }, 60000);

    executed = true;
  }
});

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

Overloading CometD with multiple publishes in a single call using Java and jQuery

Greetings, I am currently facing an issue while using the combination of cometd, jquery, and Java for testing purposes in broadcasting a message. Below is my web.xml configuration where I have utilized the Annotations implementation of cometd: <!-- Co ...

Pass Form ID To Function In A Dynamic Way

I have multiple forms on my webpage and I want to use the same ajax function for all of them. It currently works well for one form by fetching the id with getElementById and then passing it to the ajax function. My goal is to dynamically pass down the form ...

Troubleshooting: Unable to fetch CSS file in Node.js Express framework

I'm trying to access my .html file with localhost using node.js, but I'm facing an issue with loading the CSS that is included in the file. I am using the express framework for this purpose. Code: var express = require('express'); var ...

Encountering an issue with Next.js React SSR using styled-jsx: unable to access the 'state' property as

I've come across a problem that I can't seem to figure out. Despite my attempts to search for a solution here, I haven't been able to help myself. I'm new to javascript and react, so please bear with me. Issue: I'm using React (1 ...

Issues with the Lengthmenu option in Bootstrap Datatables Javascript

I'm currently facing an issue with my bootstrap datatables searchable table. Everything is working fine, except for the fact that users are unable to choose how many rows they want to see per page. The default setting of 10 results per page is not suf ...

express/node: You are unable to define headers once they have already been sent to the client

I seem to be running into a problem with my expressJS application. Every time I try to post to a specific route, I keep getting the error message Cannot set headers after they are sent to the client. I've been troubleshooting this issue but can't ...

The checkValidity function fails to identify incorrect "tel" input

In my form, I am using the checkValidity function to validate inputs. However, I have encountered an issue where the validation only works when an input with the required attribute is missing a value. It doesn't work if there is a value type mismatch, ...

Is there a way to remove the row after hitting its corresponding button?

Having trouble working with table tags in a cshtml page, particularly when appending tr and td elements using ajax. I'm unsure of how to delete a row when it's clicked on and also how to retrieve the values of inputs within each row. /// <r ...

NestJS Logger: Issue setting logger types in main.ts

When attempting to specify logger types in main.ts as illustrated in the official documentation: const app = await NestFactory.create(ApplicationModule, { logger: ['error', 'warn'], }); await app.listen(3000); I am encountering an i ...

The Slider within the Modal only becomes visible after I adjust the screen size

I am facing an issue with a slider inside a modal. The problem is that the slider does not show on the screen when the modal is opened. However, it appears when I manually resize the window. After some research, I found out that this issue is caused becau ...

Having issues with the onchange attribute in the rails text_field_tag not functioning as

Hey there! I am working on an ajax submitted form that includes only a text_field_tag. My goal is to have the form submit as soon as the user begins typing their search string. Thankfully, bandwidth and lag are not concerns since the application will be ho ...

"Observed Issue: Ionic2 Array Fails to Update in HTML Display

I am struggling with updating an array in Ionic2 and Angular2. I have tried updating it on the front end but it's not working, even though it updates perfectly on the backend (ts) as confirmed by checking the console. I need assistance with this. Her ...

Obtaining information from an AngularJS Service Response and assigning it to the Controller Scope Object

I have a basic AngularJS 1.7 application where I am successfully fetching data from a web API using an AngularJS service. However, I am running into an issue where the data is not being populated in the controller scope object. I have verified that the dat ...

Target the CSS element with a specific class only if it is not the first child within its parent

In my coding project, I have created a div.container which contains multiple p elements. Some of these p elements have the class p.special. My goal is to select the p.special elements that are not positioned at the very top of the parent container (i.e., n ...

How can you modify the HTML tags before Bootstrap overrides them?

Imagine having a code snippet like this: <style> #container ul li{ font-size:50px;} .myclass1 ul li{ font-size: 20px;} </style> <div id="container"> <ul> <li> <div class="myclass1"> ...

Creating an HTML return statement to specifically target and extract a certain string while disregarding additional data

Looking for a solution to trim a long string returned by a webpage, while ensuring essential data is not removed. Counting characters is not feasible due to the varying length of the return. The return format is as follows: GET /New%20Messenger&subti ...

I aim to utilize JavaScript to capture the constantly changing font color that is randomly generated

Is there a way to extract the font color from a table element? #FF0000 For example, it could be #568000 etc.. Here's my table <table class="mytable"> <th class=vertical bgcolor=#C0C0C0 align=center> <font color=#FF0000 size= ...

streaming audio data from a MongoDB database to an HTML audio element

As part of my current project, I am delving into the realm of creating an audio player. The concept of database storage for files is relatively new to me, as my previous experience has mainly involved storing strings. Up to this point, here's what I ...

Update the div using jq_form_remote_tag

Take a look below to see two images depicting a problem. The code snippet in my template, courtesy of j0k: <div id="listdiv"> echo jq_form_remote_tag(array( 'update' => 'listdiv', 'url' => 'shoppingl ...

Inconsistency in div height caused by positioning disparities

My demonstration shows two lines that should appear equal in height, but one ends up looking thicker due to its top position. Even just adjusting the top position by 1px can make a significant difference in how they look. Is there any way to prevent this u ...