My friend and I are working on enhancing our jQuery slideshow by adding a progress bar to show when the gallery will switch to the next image. Here is the code for our slideshow that we have written so far. We would greatly appreciate any help or suggestions. Thank you!
/* Our JavaScript Code */
$('.ppt li:gt(0)').hide();
$('.ppt li:last').addClass('last');
$('.ppt li:first').addClass('first');
$('#play').hide();
var current = $('.ppt li:first');
var interval;
$('#fwd').click( function() {
moveForward();
displayPause();
} );
$('#back').click( function() {
moveBackward();
displayPause();
} );
$('#stop').click( function() {
stopSlideshow();
displayPlay();
} );
$('#play').click( function() {
startSlideshow();
displayPause();
} );
function moveForward() {
stopSlideshow();
forwardImage();
startSlideshow();
}
function moveBackward() {
stopSlideshow();
backwardImage();
startSlideshow();
}
function backwardImage() {
current.fadeOut( 1000 );
if ( current.attr('class') == 'first' )
current = $('.ppt li:last');
else
current = current.prev();
current.fadeIn( 1000 );
}
function forwardImage() {
current.fadeOut( 1000 );
if ( current.attr('class') == 'last' )
current = $('.ppt li:first');
else
current = current.next();
current.fadeIn( 1000 );
}
function displayPause() {
$('#play').hide();
$('#stop').show();
}
function displayPlay() {
$('#stop').hide();
$('#play').show();
}
function startSlideshow() {
interval = setInterval( "forwardImage()", 5000 );
}
function stopSlideshow() {
clearInterval( interval );
}
$(function() {
startSlideshow();
} );
/* The HTML Structure */
<ul class="ppt">
<li><img src="images/show_1_banner.jpg"></img></li>
<li><img src="images/show_2_banner.jpg"></img></li>
</ul>
<div id="buttons">
<button type="button" id="back" title="Previous"></button>
<button type="button" id="stop" title="Stop"></button>
<button type="button" id="play" title="Play"></button>
<button type="button" id="fwd" title="Next"></button>
</div>
/* Custom CSS Styling */
ul.ppt {position: relative;}
.ppt li {
position: absolute;
width:770px;
height:460px;
}
.ppt img {
width:750px;
height:440px;
margin:0 auto;
display:block;
margin-top:10px;
}