carousel-slider
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -8,9 +8,20 @@ 'use strict'; | ||
var $thisCarousel = $(this); | ||
var slideHeight = $($thisCarousel).css('padding-bottom'); | ||
var slideWidth = $($thisCarousel).css('width'); | ||
var paddingBottom = +slideHeight.substring(0, slideHeight.length - 2) / +slideWidth.substring(0, slideWidth.length - 2); | ||
// set padding-bottom for each carousel-item that has a | ||
// background-image | ||
if ($thisCarousel.children('.carousel-item').children().length > 0) { | ||
var slideHeight = $($thisCarousel).css('padding-bottom'); | ||
var slideWidth = $($thisCarousel).css('width'); | ||
paddingBottom = paddingBottom * 100 + '%' || '0'; | ||
var paddingBottom = +slideHeight.substring(0, slideHeight.length - 2) / +slideWidth.substring(0, slideWidth.length - 2); | ||
paddingBottom = paddingBottom * 100 + '%' || '0'; | ||
$thisCarousel.children('.carousel-item').each(function (index, item) { | ||
if ($(item).css('background-image') !== 'none') { | ||
$(item).css('padding-bottom', paddingBottom); | ||
} | ||
}); | ||
} | ||
// replace carousel styles and functionality with stacked ones | ||
@@ -21,3 +32,2 @@ this.stopAutoSlide(); | ||
$thisCarousel.addClass('stacked'); | ||
$thisCarousel.children('.carousel-item').css('padding-bottom', paddingBottom); | ||
} | ||
@@ -31,3 +41,2 @@ | ||
var $carouselItems = $thisCarousel.find('.carousel-item'); | ||
var $dots = $thisCarousel.find('.dot'); | ||
var quant = $carouselItems.length; | ||
@@ -47,18 +56,15 @@ var waitTime = 5000; | ||
// set active dot | ||
$dots[0].classList.add('active'); | ||
// create the dots | ||
$('.dots').html(function () { | ||
var dotElements = ''; | ||
$carouselItems.each(function (index) { | ||
var active = index === 0 ? 'active' : ''; | ||
dotElements += '<span data-index="' + index + '" class="dot ' + active + '"></span>'; | ||
}); | ||
return dotElements; | ||
}); | ||
// AutoSlider | ||
var autoSlider = setInterval(function () { | ||
return slideCarousel(null, 'right'); | ||
}, waitTime); | ||
function slideCarousel(e, direction) { | ||
var $dots = $thisCarousel.find('.dot'); | ||
function restartAutoSlide() { | ||
if (autoSlider) clearTimeout(autoSlider); | ||
autoSlider = setInterval(function () { | ||
return slideCarousel(null, 'right'); | ||
}, waitTime); | ||
} | ||
function slideCarousel(e, direction) { | ||
// hide current carousel-item | ||
@@ -96,4 +102,5 @@ var opposite = direction === 'left' ? 'right' : 'left'; | ||
function onDotClick(e) { | ||
var nextIndex = this.dataset.index; | ||
function onDotClick(thisDot) { | ||
var nextIndex = thisDot.dataset.index; | ||
var $dots = $thisCarousel.find('.dot'); | ||
@@ -119,4 +126,18 @@ if (+nextIndex === +activeIndex) return; | ||
$dots.click(onDotClick); | ||
$thisCarousel.find('.dots').click(function (e) { | ||
if (e.target.classList.contains('dot')) { | ||
onDotClick(e.target); | ||
} | ||
}); | ||
var autoSlider = setInterval(function () { | ||
return slideCarousel(null, 'right'); | ||
}, waitTime); | ||
function restartAutoSlide() { | ||
if (autoSlider) clearTimeout(autoSlider); | ||
autoSlider = setInterval(function () { | ||
return slideCarousel(null, 'right'); | ||
}, waitTime); | ||
} | ||
// functions avaible to the user | ||
@@ -123,0 +144,0 @@ this.waitTime = function (time) { |
{ | ||
"name": "carousel-slider", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"main": "carousel.js", | ||
@@ -5,0 +5,0 @@ "author": "Brenton Cozby <brenton.cozby@gmail.com>", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
126065
451