Using jQuery and CSS languages, you can create a pretty good automatic slideshow for an image gallery.












<!DOCTYPE html>
<html>
<head>
<style>
#slideshow {
    position:relative;
    height:350px;
}

#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;
}
<style>
</head>
<body>


<div id="slideshow">
    <img src="html.png"  class="first" />
    <img src="css.png" />
    <img src="javascript.png" />
    <img src="jquery.png" />
</div>


<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>

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()", 1500 );
});
</script>
</body>
<html>




result:

html language css language javascript language jquery

JSFiddle







Privacy Policy