CSS slideshow with automatic horizontal image transition that seamlessly restarts

I am facing an issue with my HTML & CSS automatic horizontal slideshow. Everything works fine, except for when the last image finishes sliding and the slideshow loops back to the first image, there is a sudden jump in the appearance of the first image. How can I make this transition smoother? Is there a way to achieve this without using JavaScript?

.slider-container {
    width: 100%;
    height: 446px;
    position: relative;
    text-align: center;
    overflow: hidden;
}

.image-container {
  width: 3240px;
  height: 446px;
  clear: both;
  position: relative;
  animation-name: slider;
  animation-duration: 30s;
  animation-delay: 10s;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-direction: normal;
  animation-fill-mode: backwards;
  animation-play-state: running;
}

.slider-image {
  width: auto;
  height: 446px;
  float: left;
  position: relative;
}

@keyframes slider {
  0% {
    transform: translate(0, 0);
  }
  50% {
      transform: translate(-1080px, 0);
  }
  100% {
      transform: translate(-2160px, 0);
  }
}
<section class="row top slider-container">
 <div class="image-container">
  <img class="slider-image" src="https://dummyimage.com/1080x446/000/fff.png&text=Image+1" alt="">
  <img class="slider-image" src="https://dummyimage.com/1080x446/333333/fff.png&text=Image+2" alt="">
  <img class="slider-image" src="https://dummyimage.com/1080x446/666666/fff.png&text=Image+3" alt="">
 </div>
</section>

Answer №1

If you want to quickly solve the issue, one simple trick is to make the fourth image the same as the first one. Alternatively, you can follow a similar approach suggested by Adri1, but in that scenario, you will observe the transition back to image1.

Here's my method: repeating image-1 as the 4th image. Just remember to expand the width of .image-container by an additional 1080 px and introduce another keyframe (making it a total of 4 keyframes).

.slider-container {
    width: 100%;
    height: 446px;
    position: relative;
    text-align: center;
    overflow: hidden;
}

.image-container {
  width: 4320px;
  height: 446px;
  clear: both;
  position: relative;
  animation-name: slider;
  animation-duration: 30s;
  animation-delay: 10s;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-direction: normal;
  animation-fill-mode: backwards;
  animation-play-state: running;
}

.slider-image {
  width: auto;
  height: 446px;
  float: left;
  position: relative;
}

@keyframes slider {
  0% {
    transform: translate(0, 0);
  }
  33% {
      transform: translate(-1080px, 0);
  }
  66% {
      transform: translate(-2160px, 0);
  }
  100% {
      transform: translate(-3240px, 0);
  } 
}
<section class="slider-container">
 <div class="image-container">
  <img class="slider-image" src="https://dummyimage.com/1080x446/000/fff.png&text=Image+1" alt="">
  <img class="slider-image" src="https://dummyimage.com/1080x446/333333/fff.png&text=Image+2" alt="">
  <img class="slider-image" src="https://dummyimage.com/1080x446/666666/fff.png&text=Image+3" alt="">
   <img class="slider-image" src="https://dummyimage.com/1080x446/000/fff.png&text=Image+1" alt="">
 </div>
</section>

Answer №2

While not perfect, one potential solution is to adjust the timing and include a fourth keyframe that scrolls back to the initial image.

@keyframes slider {
  0% {
    transform: translate(0, 0);
  }
  33% {
      transform: translate(-1080px, 0);
  }
  66% {
      transform: translate(-2160px, 0);
  }
  100% {
      transform: translate(0, 0);
  }
}

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

Eliminate the Material Stepper heading

Is there a way to remove the header navigation from the material stepper? I've tried using the following CSS code without success: .mat-horizontal-stepper-header-container{display: none} You can view the stepper on Stackblitz by clicking this link: ...

How can I remove the arrow from a CSS selector?

I'm looking to enhance the appearance of a select element on my webpage, so I've crafted some custom CSS: .selectWebDropDown { background-color:Transparent; background: url(../Images/ddl_Normal.png) no-repeat right #FFFFFF !important; ...

Pass various checkboxes data in an email using PHP and $_POST

I'm having trouble sending my checkbox values via my email form as it keeps returning as "None" every time. Any assistance would be greatly appreciated! Code snippet: <form method="post" name="sentMessage" id="contactForm" novalidate> ...

Find the Nearest Value with Jquery and Swap Out the Div

When users complete a form and click "continue," they move on to the next section. At the top of the page, a heading indicates that the previous form is finished. If users click on the heading, it expands the completed form so they can edit it. For instan ...

Iframe displaying a blank white screen following the adjustment of document.location twice

I am in the process of developing a web application that I intend to integrate into my Wix website. The main components of the required web application are a text screen and a button to switch between different screens/pages (html content). However, I am ...

What iOS Printing and HTML formatter should you use and what level of sophistication is best?

Currently, I have successfully created an iOS 5 application that sends a job to the print queue. The functionality works fine and utilizes the UIMarkupTextPrintFormatter to generate the document in HTML format. At this point, I am using a simple HTML str ...

Troubleshooting problems with background-image in CSS using Javascript

My latest project involves coding to assign background images to various classes using jQuery. The image files are named in a numerical order, such as 0bg.jpg, 1bg.jpg, 2bg.jpg, and so on. for (i=0; i < 8; i++) { $('.hpCarousel:eq('+i+' ...

How to perfectly align an element within a div using Bootstrap

Utilizing bootstrap here. Currently trying to center the h1 element within the div, but so far I have been unsuccessful. It consistently remains aligned to the left. Attempts have included using bootstrap's center-block helper class, as well as the fl ...

A guide on incorporating text into a file utilizing JSP within HTML

I am working on a project that includes a JSP file and a .txt file. The JSP file contains a text field and a button, where the user can enter a text and click the button to store it in the .txt file. I have provided my code below, but I seem to be missin ...

VueJS is utilized to duplicate the innerHTML output value

Currently diving into the world of Vue, I encountered an issue while rendering an HTML text. My component template is a WYSIWYG editor. <template> <div id='editor_container'> <slot name="header" /> <div id='editor ...

Ways to reduce the size of images within a bootstrap carousel

I'm currently working on creating a carousel that will serve as a background image cover for my website, similar to the revolutionary slider in WordPress but without using a plugin. I am developing it specifically for my static website. The challenge ...

Develop a chart featuring sub-categories and column headings

I'm in the process of creating a table with subcategories and headers that resembles the image provided below: Here's what I've come up with so far: <table> <thead> <tr> <th>Item</th> & ...

Utilizing jQuery to access data stored locally

How can I retrieve and display all the values with key 'Task'? Below is the structure of the JSON data: {"Assignments":[{"AssignedBy":"537000","AssignedBy_FirstName":" JOHN","AssignedBy_LastName":"WANDER"}, {"AssignedBy":"537000","AssignedBy_Fir ...

Difficulty arises when collapsed text in Bootstrap clashes with the footer design

Hey there! I'm working on this website using Bootstrap, and I've encountered a problem. When you click the "See Wikipedia" button, the content expands and overlaps the footer in a strange way without changing the page height. I've tried adju ...

The UI does not display the html code (specifically svg) added through jquery appending

I am working with the following HTML code: <svg> <g> <rect></rect> <text> abc </text> </g> <g> <rect></rect> <text> def </text> </g& ...

The Sublime/TAG feature "Eliminate Selected Attributes from Tags" does not support the removal of "data-reactid" attributes

I am attempting to utilize TAG in Sublime Text 3 -- https://github.com/titoBouzout/Tag When I apply the "Remove Picked Attributes From Tags (in Document)" feature with class it successfully eliminates all class attributes. However, when I use it with ...

What is the method for establishing xpath for non-sequential words within a single attribute?

There is a single tag present : <span class="abc pqr and xyz"> I am looking to locate this specific tag in the DOM using xpath. I have attempted the following: //span[contains(@class,'abc pqr')]..... The term 'and' in the cla ...

Tips on incorporating background color into HTML emails dispatched via PHP mail()

Struggling to add a background color to my HTML email. I've attempted various methods: Inserting <script> tags with CSS code inside Adding bgcolor in body tags Using a CSS style sheet All to no avail. I suspect it could be the email provi ...

Make an element in jQuery draggable but always within the viewport

My issue is that when I resize the window, the element stays in its position until I start dragging it. Once I drag it and then resize the window again, it doesn't stay within its container. To better illustrate my problem, you can view a demo on Fid ...

The Highcharts Range Selector feature may encounter issues when used with multiple series

Currently, I am facing an issue with my highchart/highstock where I retrieve data from a PHP file. The problem arises when I attempt to use multiple series as the RangeSelector Buttons cease to function properly. For instance, in the example provided, the ...