Created
January 22, 2018 18:24
-
-
Save EfremovMS/56c80720e36c0b1810f94fd3cf04707b to your computer and use it in GitHub Desktop.
JS owl progress bar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function () { | |
// слайдер с прогрессом | |
// - [all] | |
var owlPromo = $('.js-promo__items'); | |
var owlPromoTimer = 9000; | |
var owlPromoSpeed = 1000; | |
function promo_start (event) { | |
var duration = owlPromoTimer; | |
if(event == 'change') { | |
duration -= owlPromoSpeed; | |
} | |
$('.promo__progress-val').css({ | |
width: '100%', | |
'transition-duration': duration+'ms', | |
}); | |
} | |
function promo_reset () { | |
$('.promo__progress-val').css({ | |
width: 0, | |
'transition-duration': '0ms', | |
}); | |
} | |
owlPromo.owlCarousel({ | |
items: 1, | |
loop: true, | |
smartSpeed: owlPromoSpeed, | |
slideBy: 1, | |
nav: false, | |
dots: false, | |
autoplay: true, | |
autoplayTimeout: owlPromoTimer, | |
onInitialized: function () { promo_start('init'); }, | |
onTranslated: function () { promo_start('change'); }, | |
onTranslate: function () { promo_reset(); }, | |
onDrag: function () { promo_reset(); }, | |
onChanged: function (event) { | |
if(event.item.index != null) { | |
var obj = $(event.target).find('.owl-item'); | |
var nextPreview = obj.eq(event.item.index + 1).children('.promo__item').data('preview'); | |
$('.next__img').attr('src', nextPreview); | |
var currentTitle = obj.eq(event.item.index).children('.promo__item').data('title'); | |
$('.next__title').text(currentTitle); | |
} | |
}, | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment