Skip to content

Instantly share code, notes, and snippets.

@clawfire
Created October 12, 2011 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clawfire/1280843 to your computer and use it in GitHub Desktop.
Save clawfire/1280843 to your computer and use it in GitHub Desktop.
jQuery Caroussel Helper
(function($){
$.fn.diaporama = function(options) {
var defaults = {
delay: 3,
animationSpeed: "normal",
controls:true
};
var options = $.extend(defaults, options);
this.each(function(){
var obj = $(this);
if($(obj).find("figure").length > 1){
var inter = setInterval(function(){nextElt(options)}, (options.delay*1000));
var sens = "right";
var pause = false;
$(obj).find("figure").hide();
$(obj).find("figure:first-child").addClass("active").fadeIn(options.animationSpeed);
// Controls
if(options.controls)
{
$(obj).after("<div class='diaporama_controls'><div class='btns'><a href='#' class='prev'>Prec.</a> <a href='#' class='pause'>Pause</a> <a href='#' class='next'>Suiv.</a></div></div>");
$(obj).siblings().find(".prev").click(function(){
clearInterval(inter);
prevElt(options);
if(!pause)
inter = setInterval(function(){prevElt(options)}, (options.delay*1000));
sens = "left";
});
$(obj).siblings().find(".next").click(function(){
clearInterval(inter);
nextElt(options);
if(!pause)
inter = setInterval(function(){nextElt(options)}, (options.delay*1000));
sens = "right";
});
$(obj).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;
}
);
}
// Affiche l'élément suivant
function nextElt(options)
{
$(obj).find("figure.active").fadeOut(options.animationSpeed, function(){
if(!$(obj).find("figure.active").is(":last-child"))
{
$(obj).find("figure.active").next().addClass("active").prev().removeClass("active");
$(obj).find("figure.active").fadeIn(options.animationSpeed);
}
else
{
$(obj).find("figure:first-child").addClass("active").fadeIn(options.animationSpeed);
$(obj).find("figure:last-child").removeClass("active");
}
});
}
// Affiche l'élément précédent
function prevElt(options)
{
$(obj).find("figure.active").fadeOut(options.animationSpeed,function(){
if(!$(obj).find("figure.active").is(":first-child"))
{
$(obj).find("figure.active").prev().addClass("active").next().removeClass("active");
$(obj).find("figure.active").fadeIn(options.animationSpeed);
}
else
{
$(obj).find("figure:last-child").addClass("active").fadeIn(options.animationSpeed);
$(obj).find("figure:first-child").removeClass("active");
}
});
}
}
});
return this;
};
})(jQuery);
@JaxProd
Copy link

JaxProd commented Jun 8, 2017

trojan in your zip file ? :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment