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

Can the value of a variable be passed as seen in the JavaScript code snippet?

I'm wondering if I'm on the right track with generating random colors when a button is clicked. Here's my code: randomColor = "#" + Math.floor(Math.random() * 16777215).toString(16); // --- more code --- changeHeaderColor() { con ...

`vertical navigation on the left side with expanding submenus`

Trying to create a navigation system on the left side of the page with submenus appearing on the right without impacting the main content. If anyone has any code snippets or resources that can help achieve this, I would really appreciate it. The objectiv ...

The function onClick does not function properly when used with the <p> element, but it works flawlessly with the <button> element

export function SignoutButton() { return ( <p onClick={() => signOut({ callbackUrl: "/" })}> <IoIosLogOut /> Logout </p> ); } I was struggling with a function in my next.js project that wasn't wo ...

Understanding the specific purpose and functionality of the "next()" parameter in express.js

As a newcomer to express.js, I have been diving into the documentation to understand its nuances. One particular aspect that caught my attention is the next parameter in express middleware, which supposedly triggers the following middleware function for th ...

Clicking on an image in a jQuery autocomplete menu will trigger a data post to an Express

My jquery autocomplete menu is functioning properly, displaying a list of books with author, title, and book image. I am now looking to enhance it by allowing users to click on the book image and then have the book title posted to an express app.post metho ...

Tips for enhancing undo/redo functionality when working with canvas drawings in React

Currently, I am working on implementing undo/redo functionality for html-canvas drawing on medical (.nii) images in a React application. The images consist of slices stored in a Uint8ClampedArray and usually have dimensions around 500 (cols) x 500 (rows) x ...

"Although disabled, input elements can still be focused on in Firefox browser

Illustrative example let userInput = document.createElement("input"); userInput.id = "user-input"; userInput.type = "number"; userInput.className = "user-number-input"; userInput.disabled = true; document.body.appendChild(userInput); .number-inp ...

Incorporating an array attribute into a current array of elements

I am currently attempting to incorporate the days of the week into an existing array of objects. To give you a visual representation, check out this image: https://i.stack.imgur.com/0jCBF.png After filtering my array to only yield 7 results, I aim to assi ...

Mapping JSON data from an array with multiple properties

Here is a JSON object that I have: obj = { "api": "1.0.0", "info": { "title": "Events", "version": "v1", "description": "Set of events" }, "topics": { "cust.created.v1": { "subscribe": { ...

Error: The parent class is not defined as an object

My program is currently attempting to utilize this.state, but I encountered an error. Can anyone provide assistance on resolving this issue? https://i.stack.imgur.com/wgxBf.png ...

How to show a picture stored in a MySQL database using PHP

I have been experimenting with displaying images uploaded to the database using a simple insert form. So far, I have managed to retrieve the image name in the "data-file". However, I am curious about how I can easily display the actual image in the same lo ...

Using Angular.js to update the `ng-model` with the value of text.textContent

There is a javascript event that dynamically updates the value of an input var posx = event.target.querySelector('input.posx'); posx.value = event.dx; This code successfully updates the html: <input type="text" ng-model="posx" si ...

Exploring the Safari browser with Polymer 2.0

Looking for some help with a question I have... I've been experimenting with the new Polymer 2.0 preview on Safari, but it doesn't seem to be working correctly. I'm using a simple code (just my-element) in the index.htm file, loading the pol ...

Incorporating custom CSS and HTML into the link is essential for enhancing the appearance of KnpMenu

I'm working with the KnpMenuBundle and I need to customize a link that has the route 'uri'=>'#'. How can I achieve this? The desired link should be styled like this: <a href="#" class="js-sub-menu-toggle"> <s ...

Attempting to update the content of a specific div element on a webpage without disrupting its current position

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>ajax div example</title> <script type="text/javascript" src="jscripts/jquery-1.6.4.min.js" ...

Withdrawal of answer from AJAX request

Is there a way to create a function that specifically removes the response from an AJAX call that is added to the inner HTML of an ID? function remove_chat_response(name){ var name = name; $.ajax({ type: 'post', url: 'removechat.php ...

Using the Croppie plugin to crop an image before uploading via jQuery Ajax in PHP

I've successfully implemented a code snippet that allows image cropping using PHP, jQuery, and Ajax with the Croppie plugin. Currently, I'm facing an issue while trying to include additional input values along with the image upload process. I ...

NG-model not visible to AngularJS Controller's filter

Finally, the code is working perfectly. It's a mystery to me. I created a custom filter to use with ng-repeat. The code is implemented within a Controller ... .controller('makeOrderController', function ($scope, $timeout, $ionicLoading) { ...

Issue with MaterialUI value prop not updating after dynamic rendering of components when value state changes

As I dynamically generate Material UI form components, I encounter an issue with updating their values. The value prop is assigned to a useState values object, and when I update this object and the state, the value in the object changes correctly but the M ...

Encountering an Issue while Deploying a create-react-app to Heroku

Despite trying various online remedies, I am still encountering an error while attempting to deploy a simple React.js app on Heroku. The app successfully builds when I execute git push heroku master, but upon opening it, I consistently receive an applicati ...