# Slideshow with CSS and JavaScript help!

**URL:** <https://forum.kirupa.com/t/slideshow-with-css-and-javascript-help/322961>\
**Category:** web dev\
**Created:** [June 10, 2011, 1:47pm UTC](https://forum.kirupa.com/t/slideshow-with-css-and-javascript-help/322961 "2011-06-10T13:47:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Butters](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Butters](https://forum.kirupa.com/u/Butters)\
**Post date:** [June 10, 2011, 1:47pm UTC](https://forum.kirupa.com/t/slideshow-with-css-and-javascript-help/322961/1 "2011-06-10T13:47:25Z")

</div>

Hi all,

I’m using CSS and JavaScript to add a simple slideshow to a website i’m working on. It just cycles through the images.

There’s 2 issues I can’t work out how to fix:

Firstly I would like to add multiple slideshows to the same page.  
Secondly I would like to make each slide clickable (when wrapping the images in the link tag it doesn’t slide through properly).

Here’s the code:

CSS in seperate CSS file:

```auto
#slideshow {
    position:relative;
    height:252px;
}

#slideshow IMG {
    position:absolute;
    top:0;
    left:0;
    z-index:8;
    opacity:0.0;
}

#slideshow IMG.active {
    z-index:10;
    opacity:1.0;
}

#slideshow IMG.last-active {
    z-index:9;
}

```

The JavaScript on the main page:

```auto
<script type="text/javascript" src="slideshow.js"></script>
<script type="text/javascript">
function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next = $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});

</script>

```

There’s also another .js file the slideshow uses.

The DIV on the main page:

```auto
<div id="slideshow">
                    <img src="slideshow/images/stunningphotos1.jpg" class="active" />
                    <img src="slideshow/images/stunningphotos2.jpg" />
                    <img src="slideshow/images/stunningphotos3.jpg" />
                    <img src="slideshow/images/stunningphotos4.jpg" />
                    <img src="slideshow/images/stunningphotos5.jpg" />
                    <img src="slideshow/images/stunningphotos6.jpg" />
                    </div>

```

Any help would be much appreciated!
