What is the best way to prevent the background-image fade effect in Chrome?

While transitioning the background-image, I noticed a difference between Chrome and Firefox. Firefox simply replaces the image instantly as expected, while Chrome adds a fade effect to the transition. Although this may be visually appealing, it introduces an unwanted functionality. How can I remove or disable this transition specifically for Chrome users?

I have searched through various search engines but have not found any solutions yet. It's possible that I am using incorrect keywords related to this topic.

To better visualize the issue, you can open the following example in different browsers:

@keyframes test {
  0% {
    background-image: url("https://placeimg.com/640/480/arch");
  }
  50% {
    background-image: url("https://placeimg.com/640/480/tech");
  }
  100% {
    background-image: url("https://placeimg.com/640/480/arch");
  }
}

div {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 600px;
  height: 300px;
  background-size: cover;
  background-position: center center;
  animation: test 3s infinite;
}
<!DOCTYPE html>
<html>
<body>
  <div></div>
</body>
</html>

Edit: While I appreciate workaround suggestions, I am primarily interested in understanding the root cause of this issue and finding a direct solution. Thank you for your answers on potential workarounds though.

Answer №1

By utilizing the content property within the <img> tag, the desired outcome can be achieved.

@keyframes test {
  0% {
content:url("https://placeimg.com/640/480/tech");  }
  50% {
    content: url("https://placeimg.com/640/480/arch");
  }
  100% {
    content: url("https://placeimg.com/640/480/tech");
  }
}


img{
-webkit-animation: test 3s infinite;
<!DOCTYPE html>
<html>

<body>
  <img>
</body>

</html>

Answer №2

give this a shot, I believe you would prefer it done in this manner

@keyframes test {
            0% {
                background-image: url("https://placeimg.com/640/480/arch");
            }
            49% {
                background-image: url("https://placeimg.com/640/480/arch");
            }
            50% {
                background-image: url("https://placeimg.com/640/480/tech");
            }
            99% {
                background-image: url("https://placeimg.com/640/480/tech");
            }

            100% {
                background-image: url("https://placeimg.com/640/480/arch");
            }
        }

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

Issue with Modal Box: Datepicker not Displaying Correctly

I have implemented a modal box in my webpage. When I click on a text field where a datepicker is added, it does not display anything. However, when inspecting the element using Chrome's developer tools, I can see that the 'hasDatepicker' cla ...

Accessing web authentication through VBA

Having some difficulties trying to access my webtext account through VBA. The first hurdle I faced was identifying the tags for the username and password input boxes. After using inspect elements, it seems like the tags are "username" and "password." Howe ...

Modifying webpage design using JavaScript for styling

Is there a way to change the css style(defined in the page source) dynamically with Java? I know it is possible to do it with JavaScript. If there isn't, are there other situations where JavaScript is the only choice developing a web app? ...

The div is lacking in height

I have 3 divs that belong to the stackContainer class: .stackContainer { position: relative; } Within these divs, I want multiple elements stacked on top of each other. To achieve this, I use the following code: .stackItem { position: absolute; ...

Can you explain the variance between a DIV using display: inline-block versus a SPAN element?

Can you explain the distinction between a DIV using display: inline-block and a SPAN? Furthermore, what sets apart a SPAN with display: block from a DIV? ...

Deactivate toggle effect by clicking on a different link

My existing JavaScript code changes the background color of a link when it is clicked: $(".button").click(function(){ $(this).css('background-color', '#555'); }); While this functionality works, I am looking to have the color tog ...

Create a container-fluid design in Bootstrap with various colors

I am aiming to create a design with a fluid container featuring different background colors on each side, separated by two columns within the container. I have visualized it in this image - do you think it is feasible? https://i.stack.imgur.com/KRc2Q.pn ...

What is the best way to dynamically update styleUrls or style properties in Angular?

One of my goals is to give users the ability to customize colors and certain styles within my Angular application. I am thinking about creating a structure like this: Structure: component-one   folder-with-css-files     style-for-component-1-fo ...

Modifying a section of the source name using jQuery continues to occur repeatedly when the window is resized

I have written a piece of code that is designed to identify the src attribute of all images within a specific div and modify the src name when the window width is less than 900 pixels. The code works perfectly when the page is refreshed, but I encounter an ...

Issue with loading background image in HTML/CSS is being caused by a Cross-Origin Read Blocking problem

As part of my project, I need to load an image from my image hosting site by using my github repository. The CSS code I am using for this task is as follows: #main-section{ background-image : url("https://github.com/<mypath>/myphoto.jpg"); } Be ...

Styling a fixed sidebar in Vue.js

I am currently working on a layout design that includes a fixed sidebar on the left side, positioned beside a container with its own grid structure. Utilizing Vue.js means each template contains <div> elements where I attempt to incorporate additiona ...

How can I align an input to the right using Bootstrap?

I found an example of a navbar that I liked and decided to copy it. Here is the code snippet: <div class="container"> <h3>Nawigacja zamknieta w kontenerze</h3> <nav class="navbar navbar-toggleable-md navbar-light bg-faded"> < ...

Layering an object on top of a clone using CSS

I am working on a webpage with a jQuery menu located at the following link: Menu To accommodate more items and have greater control, I duplicated the menu twice. However, when hovering over them, the duplication is visible in the background. Is there a ...

What is causing my nested class to be treated as a sibling rather than a child in HTML code

I have been searching for a clear answer to my query, but haven't found one yet. In my HTML script, I have nested divs structured like this: <ul id="navbar"> <li><a href='#' class='dropdown'>Rules</a> ...

Guidelines for automating button click using selenium in Python

<div class="wrapper"> <button class="w-full h-14 pt-2 pb-1 px-3 bg-accent text-dark-1 rounded-full md:rounded select-none cursor-pointer md:hover:shadow-big focus:outline-none md:focus:bg-accent-2 md:focus:shadow-small "> ...

Guide to align elements (cards) side by side in a row within a container element (div)

I have a question that bears resemblance to another one found on this site. I decided to create my own version of the Material UI Card example from https://material-ui.com/demos/cards/. You can view and edit my version on the sandbox editor by clicking he ...

What is the best way to create an arrow connecting a parent div to multiple child divs?

I'm faced with a challenge involving a reusable React list component that supports nested children. My goal is to visually connect the parent div to its direct children using arrows, similar to the image linked below. View List Component Image Below ...

I am struggling to style a form effectively with CSS grid

I am working on setting up a 2-column HTML form using CSS grid. In the first column, I have labels placed on individual rows. In the second column, I have form elements also placed on individual rows. This is my initial attempt at this task and I am sti ...

The toggle button requires two clicks to activate

I created a toggle button to display some navigation links on mobile screens, but it requires two clicks upon initial page load. After the first click, however, it functions correctly. How can I ensure that it operates properly from the start? Below is t ...

Utilize CSS Grid to adjust the size of an image

Hi there! I'm currently working on resizing an image using a CSS grid layout. Here's the CSS code I have so far: /* Reset */ * { padding: 0; margin: 0; } html { height: 100%; background-image: url("/assets/images/background.p ...