js main_slider

by Pawint Saeku @8 มี.ค. 67 16:44 ( IP : 10...34 ) | Tags : js

var $slide = $('.slide'),     $slideGroup = $('.slide-group'),     $bullet = $('.bullet');

var slidesTotal = ($slide.length - 1),     current = 0,     isAutoSliding = true;

$bullet.first().addClass('current');

var clickSlide = function() {   //stop auto sliding   window.clearInterval(autoSlide);   isAutoSliding = false;

  var slideIndex = $bullet.index($(this));

  updateIndex(slideIndex); };

var updateIndex = function(currentSlide) {   if(isAutoSliding) {     if(current === slidesTotal) {       current = 0;     } else {       current++;     }   } else {       current = currentSlide;   }

  $bullet.removeClass('current');   $bullet.eq(current).addClass('current');

  transition(current); };

var transition = function(slidePosition) {     $slideGroup.animate({       'top': '-' + slidePosition + '00%'     }); };

$bullet.on( 'click', clickSlide); //$bullet.on( 'click', console.log('work')); if (typeof autoSlide !== 'undefined') {     window.clearInterval(autoSlide); } var autoSlide = window.setInterval(updateIndex, 5000);

Relate topics