Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function(){
- var $carrousel = $('.carrousel'),
- $li = $('.carrousel li'),
- indexLi = $li.length - 1,
- i = 0, // on initialise un compteur
- $currentLi = $li.eq(i);
- $li.css('display', 'none');
- $currentLi.css('display', 'block');
- for(var j=0;j<$li.length;j++) {
- $("#switcher").append('<div class="switch" id="'+j+'"></div>');
- $('.switch').on("click", function(){
- $li.stop().fadeTo('slow', 0);
- $currentLi = $li.eq($(this).attr('id'));
- $currentLi.stop().fadeTo('slow', 1);
- $currentSwitcher = $(this);
- for (var k=0;k<$switcher.length;k++) {
- if ($currentSwitcher!=$switcher.eq(k)) {
- $switcher.eq(k).removeClass("activeswitch");
- $currentSwitcher.addClass("activeswitch");
- }
- }
- });
- }
- var $switcher =$('#switcher .switch'),
- $currentSwitcher = $switcher.eq(i);
- $('.next').on("click", function(){
- i++;
- if( i <= indexLi){
- $li.stop().fadeTo('slow', 0);
- $currentLi = $li.eq(i); //
- $currentLi.stop().fadeTo('slow', 1);
- $currentSwitcher = $switcher.eq(i);
- $currentSwitcher.addClass("activeswitch");
- for (var k=0;k<$switcher.length;k++) {
- if ($currentSwitcher!=$switcher.eq(k)) {
- $switcher.eq(k).removeClass("activeswitch");
- $currentSwitcher.addClass("activeswitch");
- }
- }
- } else {
- i = 0;
- $li.stop().fadeTo('slow', 0); // on cache les titres
- $currentLi = $li.eq(i); // on définit le nouveau titre
- $currentLi.stop().fadeTo('slow', 1); // puis on l'affiche
- $currentSwitcher = $switcher.eq(i);
- $currentSwitcher.addClass("activeswitch");
- for (var k=0;k<$switcher.length;k++) {
- if ($currentSwitcher!=$switcher.eq(k)) {
- $switcher.eq(k).removeClass("activeswitch");
- $currentSwitcher.addClass("activeswitch");
- }
- }
- }
- });
- $('.prev').on("click", function(){
- i--;
- if( i >= 0 ){
- $li.stop().fadeTo('slow', 0);
- $currentLi = $li.eq(i);
- $currentLi.stop().fadeTo('slow', 1);
- $currentSwitcher = $switcher.eq(i);
- $currentSwitcher.addClass("activeswitch");
- for (var k=0;k<$switcher.length;k++) {
- if ($currentSwitcher!=$switcher.eq(k)) {
- $switcher.eq(k).removeClass("activeswitch");
- $currentSwitcher.addClass("activeswitch");
- }
- }
- } else {
- i = indexLi;
- $li.stop().fadeTo('slow', 0);
- $currentLi = $li.eq(i);
- $currentLi.stop().fadeTo('slow', 1);
- $currentSwitcher = $switcher.eq(i);
- $currentSwitcher.addClass("activeswitch");
- for (var k=0;k<$switcher.length;k++) {
- if ($currentSwitcher!=$switcher.eq(k)) {
- $switcher.eq(k).removeClass("activeswitch");
- $currentSwitcher.addClass("activeswitch");
- }
- }
- }
- });
- function slideImg(){
- setTimeout(function(){
- if(i < indexLi){
- i++;
- } else {
- i = 0;
- }
- $li.stop().fadeTo('slow', 0);
- $currentLi = $li.eq(i);
- $currentLi.stop().fadeTo('slow', 1);
- if($currentLi==$li.eq(indexLi)) { $currentLi = $li.eq(0); }
- $currentSwitcher = $switcher.eq(i);
- $currentSwitcher.addClass("activeswitch");
- for (var k=0;k<$switcher.length;k++) {
- if ($currentSwitcher!=$switcher.eq(k)) {
- $switcher.eq(k).removeClass("activeswitch");
- $currentSwitcher.addClass("activeswitch");
- }
- }
- slideImg();
- }, 5000);
- }
- slideImg();
- $currentSwitcher = $switcher.eq(i);
- $currentSwitcher.addClass("activeswitch");
- });
Advertisement
Add Comment
Please, Sign In to add comment