javascript:
function slideSwitch() {
var $active = $('#slideshow IMG.active');
if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
// use this to pull the images in the order they appear in the markup
var $next = $active.next().length ? $active.next()
: $('#slideshow IMG:first');
// uncomment the 3 lines below to pull the images in random order
// var $sibs = $active.siblings();
// var rndNum = Math.floor(Math.random() * $sibs.length );
// var $next = $( $sibs[ rndNum ] );
$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 );
});
html
<a href="#"><div id="slideshow">
<img src="images/products/album1.jpg" alt="" class="active" />
<img src="images/products/album2.jpg" alt="" />
<img src="images/products/album3.jpg" alt="" />
<img src="images/products/album4.jpg" alt="" />
<img src="images/products/album5.jpg" alt="" />
</div></a><!-- end of slideshow -->
css:
#slideshow {
position:relative;
float:left;
width:250px;
height:250px;
margin:0px 0 10px 0;
display:inline;
overflow:hidden;
}
#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;
}
var timer = null;
$(document).ready(function() {
$('#slideshow IMG.active').hover(function() {
if(timer==null) {
timer = setInterval( "slideSwitch()", 5000 );
}
}, function() {
clearInterval(timer);
timer = null;
});
})
ASKER
ASKER
ASKER
ASKER
ASKER
JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.
TRUSTED BY
Open in new window
By :
Open in new window