Skip to content

Instantly share code, notes, and snippets.

@lineharo
Created March 28, 2017 19:55
Show Gist options
  • Save lineharo/ad08331f64c16f870a8a8f16966a256a to your computer and use it in GitHub Desktop.
Save lineharo/ad08331f64c16f870a8a8f16966a256a to your computer and use it in GitHub Desktop.
Слайдер из фоновых изображений
Full: https://tympanus.net/codrops/2013/04/17/background-slideshow/
$(document).ready(function ()
{
$(function() {
//bgSlides.init();
});
var bgSlides = (function() {
var $topslider = $('.slides');
var $items = $topslider.find('span');
var itemsCount = $items.length;
var current = 0;
var slideshowtime;
var interval = 3500;
var isStart = false;
var speed = 1600;
function init() {
$items.each( function() {
var $item = $(this);
$item.css('background-image', 'url('+$item.data('src')+')');
});
$topslider.css('background-image','none');
$items.eq(0).css('opacity', 1);
startSlides();
}
function startSlides() {
isStart = true;
clearTimeout(slideshowtime);
slideshowtime = setTimeout( function() {
nextSlide();
startSlides();
}, interval);
}
function nextSlide() {
var $oldItem = $items.eq(current);
current = current < itemsCount - 1 ? ++current : 0;
var $newItem = $items.eq(current);
$oldItem.animate({opacity:'0'},speed);
$newItem.animate({opacity:'1'},speed);
}
function stopSlides() {
isStart = false;
clearTimeout(slideshowtime);
}
return {init: init};
})();
// $('.slides').click(function() {
// $topslider.slick('slickGoTo', parseInt($topslider.slick('slickCurrentSlide'))+1);
// });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment