Desynchronized Keyframe Animations

Functioning smoothly on my personal computer but facing issues when accessed from a server. It seems to be starting out of sync for unknown reasons. Any help would be greatly appreciated. The code has only been vendor-prefixed for WebKit and has been tested in Chrome 26. Check out the demo here:

Here is the HTML:

<ul class="slides">
  <li><img src="http://placehold.it/200x100" /><span class="caption">Image 1</span></li>
  <li><img src="http://placehold.it/200x100" /><span class="caption">Image 2</span></li>
  <li><img src="http://placehold.it/200x100" /><span class="caption">Image 3</span></li>
</ul>

The CSS used is as follows:

ul.slides{
  position: relative;
  background: #000;
  height: 100px;
  width: 200px;
  padding: 0;
}
ul.slides li{
  position: absolute;
  left: 0px;
  top: 0px;
  right: 0px;
  bottom: 0px;
  height: inherit;
  width: inherit;
  padding: 0;
  margin: 0;
  -webkit-animation: slideshow 9s linear infinite;
}
ul.slides.clickpause:active li{
  -webkit-animation-play-state:paused;
}
ul.slides li:nth-child(1){ -webkit-animation-delay: 0s; }
ul.slides li:nth-child(2){  -webkit-animation-delay: 3s; }
ul.slides li:nth-child(3){  -webkit-animation-delay: 6s; }
@-webkit-keyframes slideshow{
  0%{
    opacity: 0;
    z-index: 2;
  }
  3%{
    opacity: 1;
  }
  30%{
    opacity: 1;
  }
  33%{
    opacity: 0;
  }
  34%{
    z-index: 1;
  }
  100%{
    opacity: 0;
  }
}
ul.slides li img{
  position: absolute;
  left: 0px;
  top: 0px;
  right: 0px;
  bottom: 0px;
  padding: 0;
  margin: 0
}
ul.slides li span{
  position: absolute;
  left: 0px;
  right: 0px;
  bottom: 0px;
  background: rgba(40, 40, 40, 0.8);
  color: #FFF;
  padding: 5px
}

Check out the demo here:

Please avoid solutions involving JavaScript. Thank you!

Answer №1

It's interesting to note that your animations may not always synchronize perfectly at the start.

I've discovered that using negative delays can be quite effective in maintaining synchronization. This method allows all animations to commence simultaneously, but some elements begin "in the past." Take a look at this example on jsbin:

http://jsbin.com/EreYIdE/2/edit

update with an inline example:

ul {
  background: #000;
  height: 100px;
  padding: 0;
  position: relative;
  width: 200px;
}

li {
  height: inherit;
  margin: 0;
  opacity: 0;
  padding: 0;
  position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
  width: inherit;
  
  -webkit-animation: slideshow 9s linear infinite;
  animation: slideshow 9s linear infinite;
}

li:nth-child(1) { 
  -webkit-animation-delay: -9s; 
  animation-delay: -9s; 
}

li:nth-child(2) {
  -webkit-animation-delay: -6s;
  animation-delay: -6s;
}

li:nth-child(3) {
  -webkit-animation-delay: -3s; 
  animation-delay: -3s; 
}

@-webkit-keyframes slideshow {
  0% {
    opacity: 0;
  }
  3% {
    opacity: 1;
  }
  30% {
    opacity: 1;
  }
  33% {
    opacity: 0;
  }
  100% {
    opacity: 0;
  }
}

@keyframes slideshow {
  0% {
    opacity: 0;
  }
  3% {
    opacity: 1;
  }
  30% {
    opacity: 1;
  }
  33% {
    opacity: 0;
  }
  100% {
    opacity: 0;
  }
}

img {
  margin: 0;
  padding: 0;
  position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
}

span {
  background: rgba(40, 40, 40, 0.8);
  color: #fff;
  padding: 5px;
  position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
}
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<ul>
  <li>
    <img src="http://placehold.it/200x100">
    <span>Image 1</span>

  <li>
    <img src="http://placehold.it/200x100">
    <span>Image 2</span>

  <li>
    <img src="http://placehold.it/200x100">
    <span>Image 3</span>
</ul>
</body>
</html>

Answer №2

To achieve the desired effect, don't forget to incorporate an animation trigger with javascript

Check out this Javascript demo for reference

window.onload = function (){ }

Alternatively, you can also utilize this jQuery demo

$(window).load(function(){})

Since CSS3 animations and transitions kick in right before document load, it is crucial to implement a suitable trigger.

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

Ways to ensure the menu remains fixed on a fluid website

Is there a way to prevent the main-menu from moving to a second line when resizing the page down, while still maintaining fluidity? Thank you, Ken ...

Use ng-class based on a condition

In my current project, I have a requirement to display different images based on certain conditions. For example, if condition1 is met, I need to show image1, and so on for other conditions. To achieve this, I am currently using the ng-if directive in my c ...

Issues with CSS pseudo classes :hover and :active not functioning as expected

As I attempted to create a game, an immediate CSS issue arose. It seems that the pseudo-classes I am utilizing are not functioning as intended. If you'd like to examine my code, it's available here. Try out the Fiddle CSS #button { width: ...

simplified code - toggle section visibility

$(".link1").click(function(){ $(".slide2, .slide3, .slide4, .slide5").css("opacity", 0.0); $(".slide1").fadeTo("slow", 1.0); }); $(".link2").click(function(){ $(".slide1, .slide3, .slide4, .slide5").css("opacity", 0.0); $(".slide2").fadeTo("slow" ...

The issue I'm facing is with the Infinite Scrolling Background Image zooming out of the page width. Any suggestions

I am working on a page design that requires an Infinite Scrolling Background Image with a looping effect to create the illusion of infinity. On top of this background, a content card is displayed. However, the image extends beyond the page width on smaller ...

Choosing a single radio button is simple with these steps

Trying to display radio-buttons in the code below, but encountering an issue where all radio-buttons can be checked simultaneously. The desired functionality is to only allow one radio button to be checked at a time, preventing the selection of multiple op ...

Measuring the quantity of 'table' elements with jQuery

This HTML code below defines a table structure. Now tables can be dynamically added to this structure. <div class="tableStyle myWebsiteTable"> <table cellspacing="0" cellpadding="0" id="site0" class="site active"> <thead> ...

Increase division height when mouse hovers over it

I want the height of the div to be 50px by default and change to 300px onmouseover. I have implemented this as follows: <style type="text/css"> #div1{ height:50px; overflow:hidden; } #div1:hover{ height:300px; } </style> <body> <div i ...

The image in drag and drop ghost preview is not appearing on Firefox

I want to show a ghost element instead of the default browser preview while dragging and dropping. However, in Firefox, the image inside the ghost element is not displayed during dragging. Oddly enough, if I drop it and then drag again, the image does appe ...

Two adjacent sections positioned alongside each other within a constrained, scrollable container

After successfully aligning two divs side by side using <div class="clear"></div> techniques from previous sources, I am now faced with a new challenge. I want to display two divs next to each other within a fixed-size container that allows hor ...

Modifying the Position of the Search Box within DataTables by Manipulating DOM Elements

As a newcomer to the jQuery datatables plugin, I am still learning how to use it effectively. I have connected the plugin to my tables using the following code: $(document).ready(function() $('#table_id').dataTable({ }); }); ...

CSS - Implementing responsive design to ensure optimal viewing experience on all devices

Card Matching Game Project Codepen Check out my CSS here, and find the rest of the code on Codepen since it's quite lengthy. const cards = document.querySelectorAll('.memory-card'); let hasFlippedCard = false; let lockBoard = false; let ...

Implementing CSS mapping with Spring 3.2.4 MVC sans the use of web.xml

Currently, I am working on a Spring MVC application in Eclipse with Jetty. I have opted for using annotations instead of a web.xml file. Despite trying various solutions found online, I am still unable to get my CSS to work. The location of my CSS file is ...

Website not showing correct format in Opencart

I am completely new to using Stack Overflow, so please forgive any mistakes I may make. I recently implemented an SSL certificate from Comodo on my custom-built ecommerce store that runs on the OpenCart platform. Previously, the website was functioning pe ...

Using CSS Sprites for Zoomable Element Graphics

I am faced with a situation where I have a segment of HTML code featuring images that can be resized or zoomed in simply by adjusting their width and height. My goal is to replace these images with CSS Sprites in order to load just one file instead of mult ...

Is it possible to assign a width property to a div element?

I want DivTest and IdOtherDIV to have the same width. I attempted to set properties like this: DivTest { background: #007C52; width: document.getElementById("IdOtherDIV").scrollWidth + "px.\n"; } Is there a way to achieve this (considering tha ...

Creating responsive images with Bootstrap 5

1 I am currently using Bootstrap 5 to develop a website and encountering an issue with getting images to move above text in the feature and mission sections on mobile or tablet screens. Previously, I was able to achieve this effect using the following cod ...

In Angular 4 applications, all vendor CSS files are converted into style tags at the beginning of the HTML document

In my Angular 4 project, I have integrated Bootstrap, Fontawesome, and some custom CSS. However, all these styles are rendering as separate tags at the top of my index.html file. I would like them to be combined into a single bundled CSS file for better ...

How to Customize Auto Complete Background Color of Selected Items in Bootstrap 4 Input Controls?

I'm currently struggling to figure out how to override the default white background color of a form control's autocomplete in Bootstrap. The white background doesn't align well with my dark theme. Whenever I enter something into an input fi ...

How to Make a Doughnut Chart Using CSS

For a while now, I've been working on filling in 72% of a circle with a hole cut out of the middle. Throughout this process, I have been consulting different resources - like this method for calculating and this one for other aspects. However, I’ve ...