var slideWidth=300;
var sliderTimer;
$(function(){
//показываем текст на первом слайде, т.к. он есть сразу при загрузке,
//без анимации смены слайдов
$('.slide:first .slidetext div').show();
$('.slidewrapper').width($('.slidewrapper').children().size()*slideWidth);
sliderTimer=setInterval(nextSlide,3000);
$('.viewport').hover(function(){
clearInterval(sliderTimer);
},function(){
sliderTimer=setInterval(nextSlide,3000);
});
$('#next_slide').click(function(){
clearInterval(sliderTimer);
nextSlide();
sliderTimer=setInterval(nextSlide,3000);
});
$('#prev_slide').click(function(){
clearInterval(sliderTimer);
prevSlide();
sliderTimer=setInterval(nextSlide,3000);
});
});
function nextSlide(){
var currentSlide=parseInt($('.slidewrapper').data('current'));
currentSlide++;
if(currentSlide>=$('.slidewrapper').children().size())
{
currentSlide=0;
}
$('.slidewrapper').animate({left: -currentSlide*slideWidth},300,function(){
//скрываем отыгранные тексты на всех слайдах
$('.slide .slidetext div').hide();
//отыгрываем эффект для текста на текущем слайде
$('.slide:eq('+currentSlide+') .slidetext div').each(function(){
$(this).show();
$(this).data('width',$(this).width());
$(this).css({overflow: 'hidden',width: 0}).animate({width: $(this).data('width')},500);
});
}).data('current',currentSlide);
}
function prevSlide(){
var currentSlide=parseInt($('.slidewrapper').data('current'));
currentSlide--;
if(currentSlide<0)
{
currentSlide=$('.slidewrapper').children().size()-1;
}
$('.slidewrapper').animate({left: -currentSlide*slideWidth},300,function(){
//скрываем отыгранные тексты на всех слайдах
$('.slide .slidetext div').hide();
//отыгрываем эффект для текста на текущем слайде
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.