The animation-play-state is set to 'running', however, it refuses to start playing

I'm in the process of creating a landing page that includes CSS animations, such as fade-ins. Initially setting animation-play-state: "paused" in the CSS file, I later use jQuery to trigger the animation while scrolling through the page.

While this setup works perfectly on Chrome on my Mac, attempting to run it on both Safari and Chrome on my iPhone has proven unsuccessful.

After inspecting console logs and debugging extensively, everything appears to be functioning properly except for the actual animation not running (despite the animation-play-state changing to "running").

One last detail - if I place the

$(".row").css("animation-play-state", "running");
statement before the if statement, it performs as expected.

Here's the jQuery statement in question:

//the position where I want the animation to trigger

var destinations = $('#destinations').offset().top - 300;

//the event listener

if($(window).scrollTop() > destinations) {
        $(".row").css("-webkit-animation-play-state", "running");
        $(".row").css("animation-play-state", "running");
}

Any insights on what might be causing this issue? Thank you in advance! Niv

Answer №1

Encountered an interesting problem today while attempting to create a reveal animation by changing the animation-play-state.

In addition, the animation-fill-mode: both; property was also defined.

The keyframes I used looked like this


    @keyframes fade {
        from { opacity: 0; }
        to { opacity: 1; }
    }

Despite trying various solutions, nothing seemed to work in Safari. The versions tested were 11.1.2 (13605.3.8) (Stable) and Safari Technology Preview Release 63 (Safari 12.1, WebKit 13607.1.2.1), on both Macbook and iPhone - but the result remained the same, with no animation playing.

To summarize, simply changing the animation-play-state property won't work in Safari. Instead, try altering the animation-name property.

I found a workaround using opacity and transform to reveal elements, where creating a temporary animation name helped:


    @keyframes be-hidden {
        from { opacity: 0; }
        to { opacity: 0.0000001; }
    }
    @keyframes fade {
        from { opacity: 0; }
        to { opacity: 1; }
    }
    div {
        animation-name: be-hidden;
        animation-duration: 600ms;
        animation-fill-mode: both;
        animation-delay: 500ms;
        animation-iteration-count: 1;
    }
    div.revealed {
        animation-name: fade;
    }

Assign a animation-name to a temporary animation that hides elements, then switch it to another (.revealed class)

If there are alternative ways to solve this issue, I would love to explore them.

Possibly related:

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

Tips for posting images upon clicking a div instead of a submit button

I previously had a code that allowed users to click on the submit button and have the text inside a contenteditable div passed to upload.php using JQuery, inserted into a database, and immediately displayed. Now, I want to modify this code to also handle i ...

Using JavaScript variables within the value section of a JSON is a common requirement for developers

var averageTemperature = req.params.rating; var destinationName = req.params.name; var query = { "results.name": destinationName }; var updateQuery = { $set: { "results.$.rating": averageTemperature } }; mach.update(query, updateQuery, function(err, res ...

Manipulating a textarea in jQuery by inserting a string and selecting a specific portion of it

Just as seen on SO with the B button: **bold text** Including that bold text is automatically highlighted and the cursor is placed right before the b ...

Node.js and Angular.js communication: from requests to responses

Efforts are being made to solicit data from a node.js server through angular.js. However, an unexpected challenge persists: post-data response, a stark white browser screen shows up with the JSON object in plain sight. The goal is for angular.js to acknowl ...

JavaScript - Modify input character prior to appending it to the text area

I am working on creating a virtual keyboard using jQuery. Whenever I press 'a' in the textarea, I want it to display 'z' instead. In my investigation of typing a letter in the textarea, I discovered the following sequence: keyDown ev ...

Using fancybox to send an ajax post request to an iframe

Can you send a variable to the iframe when using fancybox? This is my current setup: function fancyBoxLoad(element) { var elementToEdit = $("#" + $(element).attr("class")); var content = encodeURIComponent($(elementToEdit).oute ...

Using the JavaScript selectionchange event to target a specific element exclusively

I am looking for a way to incorporate a JavaScript selectionchange event on a specific div element. The goal is to display a highlighter box when the user selects text from the DOM. I was able to achieve this functionality for web using an onmouseup event, ...

Dynamic styling based on conditions in Next.js

After a lengthy hiatus, I'm diving back in and feeling somewhat disconnected. In short, I have encountered a minor challenge. I successfully created a navigation menu pop-out that toggles classname based on the isActive condition in React. However, I& ...

Occurrences repeating several times following the incorporation of fresh content into the DOM

I am facing an issue with my plugin. I have implemented an update method to handle new elements added to the DOM. Initially, everything works perfectly without any errors or issues. However, when a new element (div with class "box") is added to the DOM, th ...

Attempting to locate the precise jQuery selector for a specific element

Let me show you how I've set up my markup: <li class="websites" id="3"> <span class="id">3</span> <span><a href="http://www.google.com"><span class="url">www.google.com</span></a></span> ...

Changing a numeric string into a number within an Angular 2 application

Looking for advice on comparing Angular 2 expressions. I have an array of data stored as numeric strings in my database and I need to convert them to numbers before applying a condition with ngClass for styling purposes. Any suggestions on how to perform ...

Error: The function "execute" has not been declared

Hey there! I've created a Discord bot that is meant to check the status of a Minecraft server, but I'm encountering an issue with the embed. It's showing this error: UnhandledPromiseRejectionWarning: ReferenceError: execute is not defined. ...

Unable to manipulate dynamically added content using .load method

Currently, I am facing an issue with loading content via AJAX and displaying the HTML, which contains div elements, inside a parent ul. I have successfully written several functions using .click and .hover that work flawlessly on all elements except for t ...

Simple Mobile-Friendly Tabs - mobile tabs are always visible

My JavaScript skills are not the best. I have been using Easy Responsive tabs and encountered an issue on the mobile version where clicking does not hide content, but only removes the "d_active" class and adds it to another element. I believe that if the ...

Steps to clear the form in vue after the ajax request has been successfully submitted

Exploring Vue.js Web Form Validation with a Scenario If you are interested in the vue-form validator library, it can be found at https://github.com/fergaldoyle/vue-form For a demonstration of this scenario, check out the following jsfiddle link: https:/ ...

What is the process for importing a file with an .mts extension in a CJS-first project?

Here's a snippet from a fetchin.mts file: import type { RequestInfo, RequestInit, Response } from "node-fetch"; const importDynamic = new Function("modulePath", "return import(modulePath);") export async function fetch(u ...

showcase every value upon submission in the form with options to edit and delete

Is it possible to display all values submitted in a form with edit and delete buttons? Currently, only one value is being displayed at a time. Whenever a new value is displayed, it replaces the old one. How can this be fixed? You can fin ...

What is the best approach to identify duplicated objects within an array?

I have an array with a specific structure and I am looking to add non-duplicate objects to it. [ { applicationNumber: "2", id: "8cca5572-7dba-49de-971b-c81f77f221de", country: 23, totalPrice: 36 }, { applicationNumber: "3", id: "8cc ...

Tips on how to dynamically uncheck and check the Nebular checkbox post-rendering

I incorporated a nebular theme checkbox into my Angular 8 App. <nb-checkbox [checked]="enable_checked" (checkedChange)="enable($event)">Enable</nb-checkbox> I am able to update the checkbox using the Boolean variable "enable_checked". Initia ...

Tips for sending an icon as a prop in React components

I'm struggling to implement an icon as a prop while using props for "optionText" and "optionIcon". The optionText is working fine, but I'm facing issues with the OptionIcon. File where I'm creating props import Icon from ...