Glitch in the animation of the slideshow

I'm encountering a small bug in the animation of my slideshow on the webpage and I can't seem to locate it. I followed a tutorial for the slideshow from this link: https://www.youtube.com/watch?v=TzAshjkhFQw. However, I only want to display 3 slides instead of 4. The first 3 slides work fine, but the fourth slide displays as an empty background. I want the slideshow to loop after the third slide.

/* Slider */
.slider {
  display: block;
  height: 100%;
  width: 100%;
  z-index: -1;
  background-color: #1f1f1f;
  overflow: hidden;
  position: absolute;
  top: 0px;
  right: 0px;
  border-bottom: 10px solid rgb(121, 0, 0);
}

.slider > * {
  position: absolute;
  display: block;
  width: 100%;
  height: 100%;
  background-color: #1f1f1f;
  animation: slide 12s infinite;
  overflow: hidden;
}

.slide:nth-child(1) {
  left: 0%;
  animation-delay: -1s;
  background-image: url(img/slide1.jpg);
  background-size: cover;
  background-position: center;
}

.slide:nth-child(2) {
  left: 100%;
  animation-delay: 2s;
  background-image: url(img/slide2.png);
  background-size: cover;
  background-position: center;
}

.slide:nth-child(3) {
  left: 100%;
  animation-delay: 5s;
  background-image: url(img/slide3.jpg);
  background-size: cover;
  background-position: center;
}


.slide p {
  font-size: 2rem;
  text-align: center;
  display: inline-block;
  width: 100%;
  margin-top: 340px;
  color: #fff;
}

@keyframes slide {
  0% { left: 100%; width: 100%; opacity: 1;}
  5% { left: 0%;}
  25% { left: 0%;}
  30% { left: -100%; width: 100%; opacity: 1;} 
  30.0001% { left: -100%; width: 0%; opacity: 0;}
  100% { left: 100%; width: 0%; opacity: 0;}
}
<div class="slider">
      <div class="slide">
        <p>Slide1</p>
      </div>
      <div class="slide">
        <p>Slide2</p>
      </div>
      <div class="slide">
        <p>Slide3</p>
      </div>
    </div>

Any guidance or suggestions on how to fix this issue would be greatly appreciated!

Answer №1

To modify the animations, adjust the percentages and timings for each slide accordingly

@keyframes slide {
  0% { left: 100%; width: 100%; opacity: 1;}
  6.667% { left: 0%;}
  33.334% { left: 0%;}
  40% { left: -100%; width: 100%; opacity: 1;} 
  40.0001% { left: -100%; width: 0%; opacity: 0;}
  100% { left: 100%; width: 0%; opacity: 1;}
}

.slide:nth-child(2) {
  animation-delay: 3s;
}

.slide:nth-child(3) {
  animation-delay: 7s;
}

The original animation was set for 4 slides over 12 seconds, with one slide transitioning every 3 seconds. To change it to one slide every 4 seconds, adjust the animation delays and percentage values by multiplying them by 4/3.

This method of animating slides may seem rigid, so exploring alternative approaches that allow for easier slide addition and removal could be beneficial.

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

What could be the reason for the event not being triggered multiple times?

Currently, I am in the process of designing follow/unfollow buttons for various members within a system. However, I am encountering an issue where the jQuery event does not trigger after the HTML is re-rendered within the same div containing the buttons. T ...

The Limits of JavaScript Tables

Currently facing an issue with a webpage under development. To provide some context, here is the basic layout of the problematic section: The page features a form where users can select from four checkboxes and a dropdown menu. Once at least one checkbox ...

Issue with cursor behavior in contenteditable field on Chrome

Recently, I encountered an issue where the cursor would jump to the wrong place when a user clicked inside a contenteditable div, but not directly on the text. This problem seems to be isolated to newer versions of Chrome and Opera. Interestingly, when I t ...

Changing the screen size of a panel using asp.net and c#

When my screen size reaches 480px, I want to remove one menu and replace it with another. The solution I'm considering is creating two panels. In this setup, I would set menu1 to false when the screen size is less than 480px and menu2 to true. Conve ...

Tips for retrieving HTML file content as a string using JavaScript

I'm looking to retrieve the contents of an HTML file using JavaScript and store it as a string. I tried writing some code for this purpose, but unfortunately, I encountered an error: Error: Cannot find module 'xmlhttprequest' Could someone ...

Elements that are fixed are not visible on the browser's screen

Currently, I am facing an issue with two divs that have a position: fixed; property. Everything functions properly until I zoom in on the page. Typically, when you zoom in on a page, two sliders appear to allow you to view content beyond your screen. Howev ...

Retrieve the element located within a "block" element that is relative to the user's click event, without the

I'm pondering whether it's feasible, but here's my concept: Within my page, there are multiple identical blocks with the same classes, differing only in content. I am unable or unwilling to assign IDs because these blocks are dynamically g ...

What is the best way to turn off default CSS styling in KendoUI?

I am facing an issue in my application where I am using global CSS definitions for "INPUT", "SELECT", and other elements. The problem arises when I try to incorporate KendoUI widgets, as they override my default CSS styles. For instance, my CSS code looks ...

"Encountered an issue with submitting the nodejs form

edit 2 After attempting to implement the following code snippet in my nodejs application, I encountered an issue where the form data was not being successfully posted to the database: router.get('/dashboard/users/forms/competition-form/:id', en ...

The redirection to the webpage is not occurring as expected

I've been attempting to redirect another webpage from the homepage in my node server. However, the redirect isn't working as intended to link to idea.html, where the relevant HTML file is located. Can anyone assist me in identifying any errors in ...

Animating an element from its center with pure CSS

I've dedicated countless hours to uncovering a solution that can be achieved using only CSS. My goal is to create an animation on a div element where its height and width decrease uniformly when hovered over. <div class="a"></div> Above ...

Unable to pinpoint the source of the excess spacing within a form field

There appears to be some extra space in the text field of my form, extending beyond the container margin. Please refer to the image and JSFiddle http://jsfiddle.net/GRFX4/. Any thoughts on what might be causing this issue? Thank you. HTML: <div id="co ...

The synergy between HTML and JavaScript: A beginner's guide to frontend coding

I have primarily focused on server-side development of enterprise applications (Java EE, Spring framework). However, I am now exploring client-side technologies for better understanding (not necessarily to become an expert). I have studied HTML and CSS th ...

Strategies for addressing frontend challenges in Bootstrap 4

Currently, I am enrolled in a program to enhance my knowledge of Angular and have encountered a challenge. My project is utilizing the most recent version of bootstrap, which is bootstrap 4. However, I am facing issues with the main page not functioning co ...

Tips on creating a blurred background effect when an HTML popup modal is activated

Whenever I click on a button, a popup window appears. What I want is for the background to be blurred when this popup modal opens. <div class="modal" id="myModal"> <div class="modal-dialog modal-lg"> <div class="modal-content"> ...

The Nivo Slider is stealthily concealing my CSS Menu

Although this question has been previously asked, I am still unable to make it work with the solutions provided; The website in question is I have tried changing the z-index on all menu items to 99999, but they are still appearing below. <div id="sli ...

What could be causing the uneven alignment and padding of texts in my input box and select box in Bootstrap 5?

I'm facing a challenge that has me stumped. I have a form with a text input and a select drop-down, all styled using Bootstrap 5. My goal is to reduce the default left padding on these form controls by adding padding-left:0.3rem to my style definition ...

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; ...

Determining the position of p5.js input in relation to the canvas

Show me what you’ve got: function initialize() { var board = createCanvas(960,540); board.parent("drawingPad"); background('white'); var textbox = createInput(); textbox.position(10,10); textbox.parent("drawingPad"); } I’ve cre ...

Allowing horizontal scrolling in a table cell set to full width

I'm attempting to achieve the desired outcome by utilizing the code provided at What I'd like to know is why the scrolling function isn't working as expected. Instead of scrolling, it simply expands the table. To see the difference, try run ...