Transitioning Photo Galleries with CSS3

I'm looking to create a smooth transition between images in my photo gallery without relying on ":hover" or any Javascript. I'm open to exploring options with HTML5.

The slideshow animation should start automatically when the page loads, with no user input required. However, I'm having trouble with the timing in my CSS. Ideally, I want each image to fade out every 6 seconds as the next one fades in seamlessly. The animation should loop continuously after displaying the last image.

I've tried adding delays between the images to stagger the animations, but they end up overlapping too much. It seems like I have misunderstood some key concepts. Here is the CSS code I'm currently using:

#imgContainer {
height: 205px;
position: relative;
width: 300px;
}

#imgContainer img {
-moz-animation-duration: 12s;
-moz-animation-iteration-count: infinite;
-moz-animation-name: FadeInOut;
-moz-animation-timing-function: ease-in-out;
left: 0;
position: absolute;
}
#imgContainer img:nth-of-type(1) {
    -moz-animation-delay: 0s;
}
#imgContainer img:nth-of-type(2) {
    -moz-animation-delay: 6s;
}
#imgContainer img:nth-of-type(3) {
    -moz-animation-delay: 12s;
}

@-moz-keyframes FadeInOut {
    0% {
        opacity:0;
    }
    100% {
        opacity:1;
    }
}

As I am new to CSS3, any guidance or help would be greatly appreciated.

Answer №1

Great news!

After some experimentation, I found a method to create the desired effect in my slideshow. By applying individual animations to each image within the slideshow and ensuring they run sequentially in an infinite loop, I was able to achieve the result I was aiming for. Instead of relying on a single keyframe, each image now has its own unique animation.

To maintain a progression every 15 seconds in the slideshow, I adjusted the total duration of the animation to 45 seconds. The keyframes control the opacity of the images based on the current time or frame of the animation, represented by the percentage sign (%). For instance, from 2% to 32% of the 45-second duration, the first image is at 100% opacity. Between 32% and 34%, the transition of the first image from opaque to transparent begins.

The difference between the keyframes (34% of 45s) - (32% of 45s) determines the length of the transition period. Increasing this difference will result in a longer transition time.

A similar approach is applied to the second image's keyframe, with its transition starting at 33% of the 45-second animation. This slight overlap adds visual appeal, and keeping the transition time short involves calculating the difference between 33% and 35% instead of starting from 0%.

The third image follows the same pattern with its keyframe.

Remember to adjust or add the appropriate vendor prefixes for your browser and the browsers of your web audience when implementing this solution.

If you found this information useful, please consider showing your support by voting using the up-arrow icon.

Thank you! =)

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 is the best way to stack an absolutely-positioned element within the children of a sibling element?

I am currently utilizing the vue-slick-carousel package to enhance my website. Within this carousel, there are three key elements that I need to interact with. The first element is an image containing a character identified by the class slide__person. The ...

How can I trigger a PHP function from within an HTML onClick() event?

While I have come across a response on stackoverflow regarding form submission, my query pertains to a different implementation. I am in need of calling a function that registers a variable in $_SESSION[], and then redirects to another page (html/php). I ...

Bootstrap 4 Row failing to fill entire div width

I am currently designing a bootstrap 4 layout with four columns, but starting with just three. I have an outer div container and an inner row with three columns. However, when I add borders to all the containers, I notice that the row does not expand to fi ...

What are alternative ways to divide CSS without relying on CSS-in-JS and CSS modules?

Recently, I transitioned to next.js and I'm eager to develop an application with CSS styles without resorting to css-in-js or inline styling. In my exploration, I've come across two potential options: using CSS modules or importing global styles ...

What is the method for designing a relative layout that organizes elements horizontally?

Can you tell me why elements are typically arranged vertically in a column? Is it feasible to change their orientation and display them horizontally, like in a row instead of a column? ...

Achieving full white space utilization with inline block elements

When attempting to stack elements on top of each other, I encounter unwanted white space due to varying heights of the elements. I am trying to figure out how to move boxes 6 and 7 up while keeping all corresponding elements beneath them aligned properly. ...

What is the best way to increase the size of this text when an image is hovered over?

I'm looking to make the .thumb_text element grow when hovering over the <img> within the li.thumb_list. Currently, I can only achieve this effect when hovering over the text itself, not the image. In addition, the text is inexplicably becoming ...

Is there a way to transfer table row data to another table by simply clicking on the corresponding checkbox in the same row?

I'm working with a table that includes 4 fields: service, amount, tax, and action. My challenge is to have the data from any row in the first table added to a second table when its checkbox is selected. The second table should have the same fields a ...

Slider and overflow problem detected

I am currently attempting to make Unslider functional, but at present, it appears as though there is simply a stack of images on top of each other. Below is the HTML code being utilized: <div id="main"> <div class="slider"> <ul> ...

Using jQuery to generate a JSON object dynamically based on the values entered in each input field

I'm facing a situation where I need to extract data from a JSON format using PHP. However, I'm struggling with how to structure the Javascript object in order to dynamically create the JSON format. Here is my current scenario: <input title=" ...

Incorporating an HTML image into a div or table using jQuery

I am a beginner in using JQuery within Visual Studio 2013. My question is how to insert an img tag into a table or div using JQuery? For example, I have a div and I would like to generate an image dynamically using JQuery. Or, I have a dynamically create ...

What causes an AJAX call to trigger both the success and error blocks each time it is made?

I'm having trouble with uploading an image to a database using AJAX. Every time I make the call, it enters both the success and error blocks. Here's my HTML: <div> <form id="test-form" enctype="multipart/form- ...

Obtain the abbreviation inside the specified element

Currently, I have the following code snippet: <th class="day-heading mon" scope="col"> <abbr title="Lunes">L</abbr> </th> My goal is to access the abbr element and modify both its innerHTML and title attributes. How can I achiev ...

Is PHP loaded prior to the `html body`?

I'm facing a unique challenge where I am currently transferring variables from a PHP page to hidden HTML inputs. The values are extracted from these hidden inputs using a JavaScript function that is called in the following manner: <body onload=" ...

What could be causing me to receive null when trying to retrieve an element with document.getElementById, even after invoking $(document).ready(function() { ... })?

Here's a small example. I'm feeling a bit rusty with JavaScript, as it's been some time since I last worked with it. The problem I'm encountering is an error in Chrome developer tools: "Uncaught TypeError: Cannot set property 'src ...

Utilize the toggle feature by retrieving the dynamic ID from ng-repeat within the scope

Hey there! I'm currently working on a UI that contains multiple links, and when clicked, each link should toggle to display different data. The challenge I'm facing is that the data is being generated dynamically using ng-repeat. How can I ensure ...

The video player will only start playing after the source has been changed if it was already in play

I am facing an issue with my video player that has thumbnails. The problem is that the video player does not start playing the selected video unless the video is already playing. This means I have to hit the play button first, and then select the thumbnail ...

Can a single SVG file be referenced and reused multiple times in a project?

Instead of repeating these code blocks: <svg class="icon-user"> <use href="LONGFILENAME.svg#icon-user"> </use> </svg> <svg class="icon-user2"> <use href="LONGFILENAME.svg#icon-user2"> </use> </ ...

Ensure that the radio button is set to its default option when the user accesses the page

I have a model with a 'PartActionType' enum which includes Transfer, Harvest, and Dispose options. public enum PartActionType { Transfer, Harvest, Dispose } On my view page, I am displaying these options using ...

What is the best way to extract the innerHTML of every button and exhibit it in a text box?

How can I create a simpler JavaScript code for clicking buttons to input letters into a text box? Instead of creating getElementByID for each button, is it possible to use some kind of loop? <div id="alpha" > <br/> <div align="cente ...