Troubleshooting CSS3 @keyframes animation issues within Firefox's shadow DOM

I am currently working on creating a custom shimmer loader using CSS3 keyframes animation within the shadow DOM. While the shimmer effect displays perfectly in Chrome and Safari, it seems to be malfunctioning in Firefox.

Below is a concise snippet that demonstrates this issue:

 document.getElementById('myDiv').attachShadow({mode:'open'}).innerHTML = `
                <div id="myInnerDiv" class="shimmer">
                    Some text here
                </div>
                <style>
                    #myInnerDiv {
                        max-width: 200px;
                        min-height: 200px;
                    }
                    .shimmer {
                        background: #f2f3f4 linear-gradient(to right, #f2f3f4 0%, #e2e4e9 20%, #f2f3f4 40%, #f2f3f4 100%) no-repeat !important;
                        background-size: 100% 100% !important;
                        color: rgba(0, 0, 0, 0) !important;
                        animation-duration: 1s;
                        animation-fill-mode: forwards;
                        animation-iteration-count: infinite;
                        animation-name: placeholderShimmer;
                        animation-timing-function: linear;
                    }
                    @keyframes placeholderShimmer {
                        0% {
                            background-position: -200px 0;
                        }

                        100% {
                            background-position: 200px 0;
                        }
                    }
                </style>
            `
<!DOCTYPE html>
<html dir="ltr" lang="en">
    <head></head>
    <body>
        <div id="myDiv"></div>
    </body>
</html>

Answer №1

Customize your animations according to your needs. The example below demonstrates how to animate the background color and is compatible with Firefox.

document.getElementById('myDiv').attachShadow({
  mode: 'open'
}).innerHTML = `
        <div id="myInnerDiv" class="shimmer">
            Some text here
        </div>
        <style>
            #myInnerDiv {
                max-width: 200px;
                min-height: 200px;
            }
            .shimmer {
                background-size: 100% 100%;
                color: rgba(0, 0, 0, 0);
                animation-duration: 1s;
                animation-fill-mode: forwards;
                animation-iteration-count: infinite;
                animation-name: placeholderShimmer;
                animation-timing-function: linear;
            }
            @keyframes placeholderShimmer {
                0% {
                  background: red;
                }

                100% {
                    background: blue;
                }
            }
        </style>
    `
<div id="myDiv"></div>

Consider removing unnecessary !important declarations from your CSS styles, as it can lead to redundant code. Update the following section by removing !important from .shimmer -> background

    document.getElementById('myDiv').attachShadow({ mode: 'open' }).innerHTML = `
           <div id="myInnerDiv" class="shimmer">
               Some text here
           </div>
           <style>
               #myInnerDiv {
                   max-width: 200px;
                   min-height: 200px;
               }
               .shimmer {
                   background: #f2f3f4 linear-gradient(to right, #f2f3f4 0%, #e2e4e9 20%, #f2f3f4 40%, #f2f3f4 100%) no-repeat;
                   background-size: 100% 100%;
                   color: rgba(0, 0, 0, 0);
                   animation-duration: 1s;
                   animation-fill-mode: forwards;
                   animation-iteration-count: infinite;
                   animation-name: placeholderShimmer;
                   animation-timing-function: linear;
               }
               @keyframes placeholderShimmer {
                   0% {
                       background-position: -200px 0;
                   }

                   100% {
                       background-position: 200px 0;
                   }
               }
           </styl
       `
<div id="myDiv"></div>

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

Newly designed Bootstrap 4 input field with search feature positioned off-center on smaller screens

I have successfully positioned an input text next to a button as shown below: While it displays perfectly on a regular computer screen, the alignment gets skewed when viewed on a phone device: This is the functional code I am using: <!-- Add Filer Fo ...

Panel with Bootstrap Collapse feature causes a slight movement when padding is applied

After applying the collapse behavior to a panel element, I noticed that the animation stops abruptly at the padding of .panel-body, causing it to snap instantly to height. This issue can be observed in the basic example on codepen: http://codepen.io/FiveSi ...

Is it possible to represent a recursive variable using CSS?

When it comes to the html structure: <body> <div> <div> <div> ... </div> </div> </div> </body> Is there a method to create recursive variables that utilize their parent's value: body ...

Activate Click, or Pop-up Box

I've been attempting to log in to the Udemy site using JavaScript, but I'm having trouble triggering the click action on the "log in" link. Unfortunately, the .click() method doesn't seem to be working when I try to select the element. The l ...

Tips for enhancing the color saturations of cells that overlap in an HTML table

My goal is to enhance the color of overlapping cells in my HTML tables. For instance, when I click on cell 2, the .nextAll(':lt(5)') method will change the class of the next 4 cells. https://i.stack.imgur.com/mwv8x.png Next, clicking on cell 3 ...

placing additional containers at the bottom rather than on the right side

Hey there! I'm currently working on a simple website and I'm having trouble getting the duplicated form rows to appear aligned below the previous one. Here's what I have right now: var i = 0; var original = document.getElementById("dupl ...

What is the best way to ensure that the width of dropdown menu items corresponds precisely to the width of the content

I have implemented the Reactstrap drop-down menu: import React from "react"; import { Dropdown, DropdownToggle, DropdownMenu, DropdownItem, } from "reactstrap"; export default class DropDownTest extends React.Component { cons ...

How can you use ng-click to disable a div in AngularJS?

I'm looking to dynamically disable a div in AngularJS based on a certain condition. I know I can achieve this by adjusting the CSS (such as reducing contrast and color) but the div also has an ng-click property that I want to prevent from being trigge ...

Strange issue with Firefox when utilizing disabled attribute as "disabled"

I found a curious bug in Firefox: Check out (unfortunately not reproducible in jsfiddle) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> < ...

Issues with navigation functionality in Internet Explorer 8 have been identified in Twitter Bootstrap 3 RC2

I am currently using Twitter Bootstrap 3 RC2 to create a navigation bar at the top of my page, which is working perfectly fine except on IE8. In IE8, it seems like the browser is rendering the page as if it were on a smaller screen, causing the menu to co ...

Why is it that I'm encountering this basic mistake in Selenium?

I am currently using an AWS micro instance without a graphical user interface. I have accessed it through SSH. pip install selenium sudo apt-get install firefox Next, I executed the following in the Python shell: >>> from selenium.webdriver.fir ...

Issues with vertical repeating in CSS Sprites

Hey there, I'm currently working on implementing css sprites in my web application. The challenge I'm facing is that I have organized the background of my website vertically within a sprite image. Now, one specific portion of the sprite needs to ...

Troubleshooting Problem with Web Forms and Bootstrap Form Design

Currently, I am utilizing a simplified version of the Admin LTE Bootstrap Theme in an ASP.NET Web Forms Project. In this project type, only one form tag can be used per page. The form tag must encapsulate both the Top (Nav) and Bottom (Side Bar Left & Mai ...

Troubleshooting problems with the width of CSS grid underlines within a scrolling container

There seems to be an issue with the underlining border in this example not extending across the entire width of the container. Any suggestions on how to resolve this would be greatly appreciated. .outer-container { width: 200px; overflow: auto; } . ...

What is the best way to adjust the spacing in my bootstrap Navbar? I am struggling to make it stretch to the entire width of the screen

I am currently working on a website project where I want to have a navigation bar that spans the full width of the screen with a black background. I also need the links to be centered and evenly distributed within the navbar. My main issue right now is re ...

Creating a full-height page with collapsible content using Bootstrap 4 and flex

I'm attempting to create a collapsible div with a fixed height within a full-height page using flex and bootstrap 4 (also encountering the same issue with bootstrap 3). The current code snippet functions correctly on Firefox, but encounters a problem ...

I aim to place my :after content in mobile view or lower resolutions

I have a testimonial section built with HTML and CSS. You can view the demo on JSFIDDLE HERE. In the mobile view, I am facing an issue where the ":after" content is not aligning properly or appears misplaced. I'm looking for ideas to ensure that it re ...

CSS animations - transitioning opacity in and out

Looking to add some CSS animations to a menu but running into some issues. I've got the code below for the menu to fade in on hover, but can't quite figure out how to make it fade out smoothly as well. I've tried a few approaches, but all I ...

Minimize the gap between icon and text on paper-icon-item in Polymer

Is there a way to decrease the spacing between the icon and text in paper-icon-item? I'm looking for a solution to this issue. https://i.sstatic.net/kZ9sy.png I attempted the following: paper-icon-item { --paper-item-icon: { padding-right: 0; ...

What are the best methods for aligning pseudo elements vertically?

I am facing an issue with the placement of a before and after pseudo element for articleSubTitle. The problem occurs when the text from articleSubTitle wraps to a new line within a small container or on mobile devices. This causes the after element to appe ...