1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| <script>
( function( $ ){
$.fn.diaporama = function( opts ) {
var defaults = {
delay: 10,
animationSpeed: 5000,
controls:true
};
var options = $.extend( defaults, opts );
return this.each( function( i, item ){
// Affiche l'élément suivant
function nextElt(options)
{
$(item).find("li.active").fadeOut('fast');
if (!$(item).find("li.active").is(":last-child"))
{
$(item).find("li.active").next().addClass("active").prev().removeClass("active");
$(item).find("li.active").fadeIn('fast');
}
else
{
$(item).find("li:first-child").addClass("active").fadeIn('fast');
$(item).find("li:last-child").removeClass("active");
}
}
// Affiche l'élément précédent
function prevElt(options)
{
$(item).find("li.active").fadeOut('fast');
if (!$(item).find("li.active").is(":first-child"))
{
$(item).find("li.active").prev().addClass("active").next().removeClass("active");
$(item).find("li.active").fadeIn('fast');
}
else
{
$(item).find("li:last-child").addClass("active").fadeIn('fast');
$(item).find("li:first-child").removeClass("active");
}
}
if ( $(item).find( "li" ).length > 1 ){
var
inter = setInterval( function(){ nextElt( options ) }, ( options.delay*1000 )),
sens = "right",
pause = false;
$(item).find("li").hide();
$(item).find("li:first-child").addClass("active").fadeIn(options.animationSpeed);
// Controls
if ( options.controls )
{
$(item).after(
`<div class='diaporama_controls'>
<table border='0' style='text-align:center;' width='100%'>
<tr>
<td width='15%'>
<a href='#' class='prev'>Prec.</a>
</td>
<td>
<a href='#' class='pause'>Pause</a>
</td>
<td width='15%'>
<a href='#' class='next'>Suiv.</a>
</td>
</tr>
</table>
</div>`
);
$(item).siblings().find(".prev").on( 'click', function(){
clearInterval(inter);
prevElt(options);
if (!pause) inter = setInterval( function(){ prevElt( options )}, ( options.delay*1000 ));
sens = "left";
});
$(item).siblings().find(".next").on( 'click', function(){
if (!pause) inter = setInterval(function(){nextElt(options)}, (options.delay*1000));
sens = "right";
});
$(item).siblings().find(".pause").toggle(
function(){
$(this).removeClass("pause").addClass("play");
clearInterval(inter);
pause = true;
},
function(){
$(this).removeClass("play").addClass("pause");
inter = setInterval(function(){ (sens == "right")?nextElt(options):prevElt(options)}, (options.delay*1000));
pause = false;
}
);
}
}
});
};
})(jQuery);
$(function(){
$(".diaporama").diaporama({
animationSpeed: 5000,
delay: 8
});
});
</script> |
Partager