Presentation: Troubleshooting Ineffective CSS3 Transitions

I have created a basic slideshow that can accommodate multiple images. Clicking on an image should move to the next slide, and once the last image is clicked, it should loop back to the first slide.

The functionality of transitioning between slides seems to work fine when returning to the first slide. However, I am facing issues implementing a CSS fade transition during each slide change.

I suspect there might be something missing in my CSS code. Any suggestions on what could be causing this problem?

Here's the Fiddle link for reference: http://jsfiddle.net/databass/76nZ7/13/

Below is the HTML, JavaScript, and CSS code snippets. Thank you!

HTML:

<div class="content">
    <img src="http://b.vimeocdn.com/ts/254/218/254218511_640.jpg" width="640"  height="360" />
</div>
<div class="content notcurrent">
    <img src="http://b.vimeocdn.com/ts/254/218/254218512_640.jpg" width="640" height="360" />
</div>
<div class="content notcurrent">
    <img src="http://b.vimeocdn.com/ts/254/218/254218513_640.jpg" width="640" height="360" />
</div>

JavaScript:

/*
 When the page loads, execute a function that assigns a sequence to each child slide 

 When a slide is clicked, the next slide will appear.
 On page load, the first slide will be shown

 Each slide should transition with fade-out/fade-in

*/

(function () {
    var slides = document.getElementsByClassName("content");
    slides[0].style.display = 'block';

    //convert collection of slide elements to an actual Array, and iterate through each slide
    Array.prototype.slice.call(slides).forEach(function (slideElement, slideSequence) {
        //execute this function for each slide. 
        (function () {
            // helper function to get the slide sequence. 
            // return 0 if we've gone through eevery slide
            var getNextSequence = function () {
                if (slideSequence + 1 === slides.length) {
                    return 0;
                } else {
                    return slideSequence + 1;
                }
            }
            // add a listener to each slide.
            slides[slideSequence].addEventListener("click", function () {
                slides[slideSequence].className = 'content notcurrent';
                slides[getNextSequence(slideSequence)].className = 'content current';
            });
        })();
    });
})()

CSS:

.content {
    width: 640px;
    height: 360px;
    position: absolute;
    top: 0;
    left: 0;
    transition: opacity .5s ease-in-out;
    -moz-transition: opacity .5s ease-in-out;
    -webkit-transition: opacity .5s ease-in-out;
}
.notcurrent {
    -moz-opacity: 0;
    -webkit-opacity: 0;
    opacity: 0;
    display: none;
}

.current {
    -moz-opacity: 1;
    -webkit-opacity: 1;
    opacity: 1;
}

Answer №1

Assign .current a z-index of 10 and remove the display: none; from .notcurrent. Next, ensure that the first item is styled as .current when the page initially loads.

Take a look at this demo to see it in action: http://jsfiddle.net/76nZ7/18/

Answer №2

html:

<div class="section active">
   ...
</div>
<div class="section inactive">
   ...
</div>
<div class="section inactive">
   ...
</div>

css:

.section {
    ...
}
.inactive {
    -moz-opacity: 0;
    -webkit-opacity: 0;
    opacity: 0;
}
.active {
    -moz-opacity: 1;
    -webkit-opacity: 1;
    opacity: 1;
    z-index: 1;
}

http://jsfiddle.net/dvdyakonov/76nZ7/19/

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

Verifying the URL to determine if it includes the specific string needed to modify the Jade theme in

I am currently exploring ways to check if a URL string is present in an express application, in order to initiate a theme change. At the moment, I have a basic router.get function: router.get('/', function(req, res, next) { res.render(' ...

Unable to assign a local variable in Jquery .ajax() function to a global variable

Check out this example of a jQuery AJAX code: $(document).ready(function() { var custom_array = new Array(); $.ajax({ url: 'data.json', type: 'get', dataType: 'json', success: function(response) { $ ...

Customize Your Calendar: A Guide to Disabling Dates with Pikaday.js

Wondering how to disable specific days on a calendar? Look no further! Here's a solution using the `disableDayFn` option from Github: disableDayFn: callback function that gets passed a Date object for each day in view. Should return true to disable s ...

What is the best way to vertically align the dropdown button with the other text boxes?

I'm currently utilizing a basic bootstrap template from getbootstrap.com. I am having trouble properly aligning the account type dropdown in this section. Additionally, the dropdown list items are not correctly aligned with the dropdown button. Any as ...

Restrict the height of a division based on the adjacent division

Within the parent div, I have two child div elements that are meant to be positioned side by side. The first element contains an image which loads dynamically, meaning its height is unknown in advance. I want the parent div's total height to match the ...

Display substitute text for the date input field

When using input types date and datetime-local, the placeholder attribute does not work directly. <input type="date" placeholder="Date" /> <input type="datetime-local" placeholder="Date" /> Instead, the ...

Adjusting my menu layout causes my header image to be partially covered

I've been trying to make my menu fixed at the top of my website, but it keeps overlapping into my header image and doesn't look right. I've experimented with different solutions, but nothing seems to work. Here's the CSS code I used th ...

Tips for transforming an SQL Server query into JSON format

I need to construct a table in a view utilizing the output of this particular SQL Query SELECT f.empresaid, e.fantasia AS Company, f.filialid, f.fantasia AS Branch, u.consultorid ...

The Vite build tool creates unique CSS module classes for each component

Is it possible to set the CSS module class name in the index.js file generated during the Vite build process? I am developing with multiple themes and a single-entry JS file. Currently, this is the output I get when trying to build the project: Index.js & ...

Unable to create follow/unfollow feature with jquery ajax

Issue: While the database part for following and unfollowing actions is functioning correctly, there seems to be a problem with the jQuery and Ajax section. The follow button changes to unfollow (with some CSS styling) only after refreshing the page, rathe ...

Adjust the aesthetic based on whether the field is populated or empty

I have a simple text field on my website that triggers a search when the user inputs a value. I am wondering if it is possible to style the text field differently depending on whether it is empty or has content. Specifically, I want to change the border c ...

Using Jquery to insert an if statement within the .html element

Trying to implement jQuery to replace html content within an object, but struggling with incorporating an if statement. Like this: $(this).html("<select id=\'status\' name=\'status[]\' multiple><option valu ...

Place two divs within a parent div that can adjust its width dynamically

Within this lengthy div, there are 4 elements arranged as follows: icon (fixed width) item_name [needs to be accommodated] item_type [needs to be accommodated] item_date (fixed width) I am currently attempting to find a way to ensure that the it ...

Enhance Your Joomla 2.5 Website with Custom CSS Specifically for iPad Viewing

Is there a way to load a specific CSS file when accessing my Joomla website through an iPad? I am running Joomla version 2.5. Although I have set up style-sheets for browsers like Internet Explorer and Firefox, I am unsure how to target the website to lo ...

Obtain an oAuth token through the use of npm

Recently, I've been working on a nodeJS service to fetch an OAuth token from a server. Unfortunately, I keep encountering errors when running the function below: var express = require('express') var http = require('http'); var htt ...

Is there a way to utilize an AXIOS GET response from one component in a different component?

I'm having trouble getting my answer from App.tsx, as I keep getting an error saying data.map is not a function. Can anyone offer some assistance? App.tsx import React, {useState} from 'react'; import axios from "axios"; import {g ...

Place the menu within the image, positioned at the bottom

Could someone help me with placing a menu at the bottom of an image using HTML, CSS and Bootstrap 4? I have limited CSS knowledge and need assistance. Currently, my navbar is located below the image but not within it like this: I am looking to achieve so ...

Coloring vertices in a Three.js geometry: A guide to assigning vibrant hues

This inquiry was previously addressed in this thread: Threejs: assign different colors to each vertex in a geometry. However, since that discussion is dated, the solutions provided may not be applicable to current versions of three.js. The latest versions ...

Creating HTML code for a mobile responsive design

I am facing an issue with my clinic webpage where the images appear differently on PC and mobile devices. I am new to HTML and CSS, so I tried using max-width: 100% but it didn't work. The code was originally created by someone else and I need help fi ...

Is it possible to use a += operator with attr() and val() functions in JavaScript?

Ever since I switched to jQuery, my development process has significantly sped up. However, there is one task that has become a bit more time-consuming: appending a string to an attribute or value. For instance, if you wanted to add a letter to the value ...