What is the best way to end a CSS image slideshow on its final image?

My slideshow consists of 3 images, each with different texts. I'm trying to figure out how to stop the autoplay feature when the last image is displayed, so it doesn't fade out and disappear. Below is the code snippet:

HTML section:

<div class="slide-container">    
<img class="slide1" src="images/1banner.jpg">
<img class="slide2" src="images/2banner.jpg">
<img class="slide3" src="images/3banner.jpg">
</div>

CSS section:

.slide-container {
position: relative;
float: right;
height: 150px;
width: 950px;
background: url('banner-back2.jpg');
}

.slide-container img {
position: absolute;
top: 0;
left: 0;
height: 150px;
width: 950px; 
opacity: 0;
}

.slide1 { -webkit-animation: fade 12s;}
.slide2 { -webkit-animation: fade 12s 4s;}
.slide3 { -webkit-animation: fade 12s 8s;}

@-webkit-keyframes fade {
0% { opacity: 0; }
10% { opacity: 1; }
20% { opacity: 1; }
30% { opacity: 0; }
100% { opacity: 0; }
}

Answer №1

To enhance the visual appeal, you may want to incorporate a secondary fade animation that remains visible and can be applied to the final slide:

.slide-container {
position: absolute;
float: right;
height: 170px;
width: 960px;
background: url('banner-background.jpg');
}

.slide-container img {
position: relative;
top: 0;
left: 0;
height: 170px;
width: 960px; 
opacity: 0;
}

.slide1 { -webkit-animation: fade-in 12s;}
.slide2 { -webkit-animation: fade-in 12s 4s;}
.slide3 { -webkit-animation: fade-out 12s 8s; -webkit-animation-fill-mode:forwards; }

@-webkit-keyframes fade-in {
0% { opacity: 0; }
10% { opacity: 1; }
20% { opacity: 1; }
30% { opacity: 0; }
100% { opacity: 0; }
}
@-webkit-keyframes fade-out {
0% { opacity: 0; }
10% { opacity: 1; }
100% { opacity: 1; }
}

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

Calculating the median in JavaScript utilizing a for loop

Currently, I am in the process of learning JavaScript. My goal is to calculate the median of a set of numbers that I input through a prompt when I click the button labeled "find median". function CalculateMedia() { var n = prompt("Enter the number of e ...

How can I properly integrate jQuery libraries, along with CSS, in a create-react-app project?

I'm currently working on incorporating the select2 jquery library into my React application, which was created using create-react-app. After adding jquery and select2 to my package.json file, I was able to get the javascript functionality to work pro ...

Discover the process of creating a dynamic mailto link using AJAX and HTML

One of my tasks involves extracting email addresses from an XML document using AJAX, and then displaying them on a webpage as clickable links for sending emails. Here is a snippet of JavaScript code I am working with: emailobj = listings[i].getElementsBy ...

How should one correctly align various classes in a cascading manner within CSS?

Here is an interesting challenge - I want each of these buttons to have their background image change when hovered over. However, I'm struggling with the class setup in my code. I've been trying to understand how to distinguish between divs and c ...

Bootstrap button statuses confirmed

I am trying to implement a checked state for group checkboxes in Bootstrap 3.0.2. documentation This is the HTML code snippet: <div class="btn-group" data-toggle="buttons"> <label class="btn btn-default"> <input type="check ...

I want to adjust the size of a <div> element as an image is being resized using Bootstrap's "img-responsive" class

When adjusting the browser size, the images are resized which is great because it's exactly what I intended. However, the lower part of the black area does not resize accordingly. This results in a black area appearing under the images when viewed on ...

What is the best way to ensure that my grid remains contained within its designated area?

I need to incorporate a grid of 16x16 or 64x64 into my layout without it overflowing. I'm considering using flexbox, but unsure of the implementation process. My goal is to have the grid resize based on the container size rather than exceeding its bou ...

Tips for activating a function during a click on the download button within an audio tag in HTML

Is there a way to track the number of downloads when using an audio tag with a download option? Which event handler should I use for this task and how can I implement it? I have already set up a fully functional back end API, but I am struggling to unders ...

Accordion section appears on the webpage as it is loaded

I am currently working on implementing an accordion feature for my webpage. Everything is functioning correctly when I click the button, but there is one issue - the div opens automatically when the page loads. My goal is to have the div closed initially a ...

The section cannot be shown in a flex layout within a grid container

My goal is to showcase a grid layout containing multiple sections within a div, but I'm encountering an issue where the sections are only displaying as blocks. I am seeking assistance in making the second portion of the data appear flexed. Currently, ...

Troubleshooting a Selected Menu Problem in jQuery CSS

Hello, I have implemented a jQuery script to change the color of a menu item when it is selected: .selected{ background-color: red; } $("#nav-container>li").click(function(){ $(this).addClass('selected') .siblings() ...

Designing a function for downloading QR images via the goqr.me API

I'm currently working on integrating dynamically generated QR Code images into my website using the API. I want to offer users the option to download the image by clicking a button, utilizing the download attribute in a hyperlink. However, instead o ...

How can buttons be replicated in an angular-friendly manner?

I need to implement a follow button functionality for a specific user that should toggle its text between "Follow" and "Followed" when clicked. The follow button may appear in various modules across the page, and when clicked, it should update in all insta ...

Updating Kendo Treeview's data source dynamically

I am working with a kendoTreeView connected to an OData source, following the demo on the official site. However, I encounter an issue when trying to change the dataSource of the kendoTreeView. Despite changing the tree successfully, all nodes are displaye ...

What is the method for generating a custom tag (similar to a class) within an option contained in a SELECT element?

I need to create a select box with two options: cars or boats. Here is my initial idea: <select> <option value="1" class="cars">Car1</option> <option value="2" class="boats">Boat1</option> <option value="3" class="ca ...

What is a simple way to ensure that my image retains its square shape on a responsive design without having to use numerous media queries?

I've been searching for solutions to my issue, but none of them have worked for me so far. I am working on a form where users can edit or add images, and I want each image to be displayed as a square regardless of the device being used (desktop, mobil ...

Tips for organizing a Bootstrap 4 menu overflowing with elements

I'm struggling to figure out how to organize a Bootstrap 4 menu with numerous links. Currently, when I include too many links, the navbar disregards the container and expands its width beyond the container. Here is an image for better clarification: ...

iOS iframe remains unscrollable only when switching from portrait to landscape orientation

I have a scrollable iframe set up on iOS like this: <div style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; overflow: scroll; -webkit-overflow-scroll: touch; ..."> <iframe style="height: 600px, ..."> </iframe> </d ...

Image of outer space enclosed by a circular boundary

Check out this fiddle I created here. It's a simple concept of an image inside a red circle. Is there a way to add some spacing around the image within the circle? This is the markup I currently have: <div style=" width: 50px; he ...

Creating a dynamic Bootstrap navigation bar using PHP

I created a website using bootstrap, but now I want to add more dynamic features. The tutorial I'm following for this does not involve the use of bootstrap. Am I missing something obvious here? Could you please review my code? (To avoid overloading t ...