Created
May 29, 2018 18:49
-
-
Save TrywaR/0ecfb267ce9dc3356905b66d87f8e2bc to your computer and use it in GitHub Desktop.
[ jQuery ] mini slider
This file contains hidden or 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
// Микро слайдуля | |
var | |
step = 4, // Количество слайдов для показа | |
time = 4000, // Через какой время менять слайды | |
portfolio_slider = $('#portfolio_slider ._slider_elems'), //Слайдер | |
start = 0, //Текущий активный элемент | |
length = $('#portfolio_slider ._slider_elems > *').length //Количество слайдов | |
function portfolio_slider_function(){ | |
stop = start+step | |
to_start = stop - length | |
portfolio_slider.find('>*').removeClass('active') | |
portfolio_slider.find('>*:eq('+start+')').addClass('active') | |
portfolio_slider.find('>*:gt('+start+')').addClass('active') | |
portfolio_slider.find('>*:gt('+(stop-1)+')').removeClass('active') | |
if (to_start === 0) | |
start = 0 | |
else | |
start = stop | |
if (to_start > 0){ | |
portfolio_slider.find('>*:lt('+to_start+')').addClass('active') | |
start = to_start | |
} | |
//Индексирование активных | |
portfolio_slider.find('.active').each(function(index) { | |
portfolio_slider.find('._index_'+index+'').removeClass('_index_'+index+'') | |
$(this).addClass('_index_'+index+'') | |
}) | |
} | |
portfolio_slider_function() | |
//Останавливаем при наведении | |
var portfolio_slider_timer = setInterval(portfolio_slider_function, time) | |
portfolio_slider.on('mouseover', function () { | |
window.clearInterval(portfolio_slider_timer) | |
}) | |
portfolio_slider.on('mouseout', function(){ | |
portfolio_slider_timer = setInterval(portfolio_slider_function, time) | |
}) | |
// Микро слайдуля x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment