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:
#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:
<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:
<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!