Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6126621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:23:54+00:00 2026-05-23T16:23:54+00:00

I am trying to get images in a slideshow to crossfade by using CSS3

  • 0

I am trying to get images in a slideshow to crossfade by using CSS3 transitions. I have the slideshow working and I know how to use transitions, but I don’t know how to get the CSS and Javascript to work together to accomplish this. I am relatively new to Javascript so simplified answers are greatly appreciated.

Javascript:

var images = new Array()
images[0] = "img/1.jpg";
images[1] = "img/2.jpg";
images[2] = "img/3.jpg";
images[3] = "img/4.jpg";
images[4] = "img/5.jpg";
var timer = setInterval(checkImage, 3000);
var x=0;

function checkImage()
{
    if (x>4)
    {
        x=0;
        changeImage();
    }
    else
    {
        changeImage();
    }
}

function changeImage()
{
document.getElementById("slideimg").src=images[x]
x++;
}

HTML:

<img src="img/5.JPG" width="400" height="300" id="slideimg">
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:23:55+00:00Added an answer on May 23, 2026 at 4:23 pm

    Since you’re asking for the whole thing including CSS, here’s a working demo (requires CSS3 transition-capable browser such as Chrome, Safari or Firefox 4+): http://jsfiddle.net/jfriend00/cwP5Q/.

    HTML:

    <div id="container">
    <img id="slideimg0" class="slide showMe" src="http://photos.smugmug.com/photos/344287800_YL8Ha-S.jpg">
    <img id="slideimg1" class="slide" src="http://photos.smugmug.com/photos/344287888_q22cB-S.jpg">
    <img id="slideimg2" class="slide" src="http://photos.smugmug.com/photos/344284440_68L2K-S.jpg">
    <img id="slideimg3" class="slide" src="http://photos.smugmug.com/photos/344286315_oyxRy-S.jpg">
    <img id="slideimg4" class="slide" src="http://photos.smugmug.com/photos/344285236_hjizX-S.jpg">
    </div>
    

    CSS:

    #container {position: relative; font-size: 0;}
    .slide {
        border: none; 
        opacity: 0; 
        position: absolute; 
        top: 0; 
        left: 0;
        -webkit-transition: opacity 2s linear;
        -moz-transition: opacity 2s linear;
        -o-transition: opacity 2s linear;
        transition: opacity 2s linear;
    }
    .showMe {opacity: 1;}
    

    JS (runs when page is ready):

    var timer = setInterval(nextImage, 4000);
    var curImage = 0;
    var numImages = 5;
    
    function nextImage() {
        var e;
        // remove showMe class from current image
        e = document.getElementById("slideimg" + curImage);
        removeClass(e, "showMe");
    
        // compute next image
        curImage++;
        if (curImage > numImages - 1) {
            curImage = 0;
        }
    
        // add showMe class to next image
        e = document.getElementById("slideimg" + curImage);
        addClass(e, "showMe");
    }
    
    function addClass(elem, name) {
        var c = elem.className;
        if (c) c += " ";  // if not blank, add a space separator
        c += name;
        elem.className = c;
    }
    
    function removeClass(elem, name) {
        var c = elem.className;
        elem.className = c.replace(name, "").replace(/   /g, " ").replace(/^ | $/g, "");  // remove name and extra blanks
    }
    

    If you were going to do this for real, you should use a class library like jQuery or YUI which will make animations both easier and work in all browsers, not just CSS3 capable browsers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have css hover over images for my tabs and I'm trying to get
Im trying to write something to get my images to show correctly. I have
I ask this question, since I am trying to get the images I have
I'm having some major headache trying to apply CSS3 transitions to a slideshow trough
Im trying to get my images to animate on mouse over (hover) but for
I'm trying to get the captions from images in Wordpress but I can't find
I am using a nice jquery slideshow plugin I found and trying to get
I am trying to get three images to connect for my content box but
I have a slideshow built using the jbgallery script that I am trying to
I am trying to implement a slideshow using jQuery I have a button called

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.