Skip to content

Instantly share code, notes, and snippets.

@brunopulis
Created March 20, 2015 15:08
Show Gist options
  • Save brunopulis/0a13a43eaaf122e44a19 to your computer and use it in GitHub Desktop.
Save brunopulis/0a13a43eaaf122e44a19 to your computer and use it in GitHub Desktop.
Slider with pure jQuery no need plugin.
var main = function(){
var dropdownToggle = $('.dropdown-toggle');
// Event Handler
dropdownToggle.on('click', function(){
$('.dropdown-menu').toggle();
});
// Event Handler
$('.arrow-prev').click(function(){
var currentSlide = $('.active-slide'),
prevSlide = currentSlide.prev(),
currentDot = $('.active-dot');
prevDot = currentDot.prev();
if( prevSlide.length == 0 ) {
var prevSlide = $('.slide').last(),
prevDot = $('.dot').last();
}
currentSlide.fadeOut(600).removeClass('active-slide');
prevSlide.fadeIn(600).addClass('active-slide');
currentDot.removeClass('active-dot');
prevDot.addClass('active-dot');
});
// Event Handler
$('.arrow-next').click(function(){
var currentSlide = $('.active-slide'),
nextSlide = currentSlide.next(),
currentDot = $('.active-dot'),
nextDot = currentDot.next();
if(nextSlide.length == 0){
nextSlide = $('.slide').first();
nextDot = $('.dot').first();
}
currentSlide.fadeOut(600).removeClass('active-slide');
nextSlide.fadeIn(600).addClass('active-slide');
// Change de dots when a click in buttons arrow.
currentDot.removeClass('active-dot');
nextDot.addClass('active-dot');
});
};
$(document).ready(main);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment