Skip to content

Instantly share code, notes, and snippets.

@Xeodee
Created September 7, 2011 01:22
Show Gist options
  • Save Xeodee/1199498 to your computer and use it in GitHub Desktop.
Save Xeodee/1199498 to your computer and use it in GitHub Desktop.
Slider
var clicked = false,
i = -1,
y = $(".contentContainer").length,
y2 = y+2,
z = y-1;
$(".sliderHolder").css("width", $(window).width());
$(".contentContainer").css("width", $(window).width());
$(".homeSlider").css("width", $(window).width()*y2);
$('.contentContainer').eq(1).clone().appendTo('.homeSlider');
$('.contentContainer').eq(y-1).clone().prependTo('.homeSlider');
$('.contentContainer').eq(1).clone().prependTo('.homeSlider');
$('.contentContainer').eq(2).remove();
function slideA(){
$('.content').eq(0).remove();
$(".homeSlider").animate({marginLeft: -parseInt($(".sliderHolder").css("width"))});
}
function content(){
$('.content').fadeIn();
$('.clickMe').fadeIn();
}
function autoSlide(){
if(!clicked){
if(i === -z){
$('.homeSlider').animate({
marginLeft: '-='+$(window).width()
}, function(){
$(".homeSlider").css("margin-left", -parseInt($(window).width()));
i = -1;
});
} else {
$('.homeSlider').animate({
marginLeft: '-='+$(window).width()
});
--i;
}
setTimeout('autoSlide()', 7000);
}
}
function intro(){
$('.content').eq(0).fadeIn('slow').delay(2500).fadeOut('slow');
setTimeout('slideA()', 5000);
setTimeout('content()', 6000);
}
var slideTimer = setTimeout('autoSlide()', 13000);
setTimeout('intro()',1000);
$(window).bind("resize", resizeWindow);
function resizeWindow( e ) {
var x = $(window).width(),
x2 = y2*x;
if ( x > 960 ){
$(".sliderHolder").css("width", x);
$(".contentContainer").css("width", x );
$(".homeSlider").css("width", x2);
$(".homeSlider").css("margin-left", parseInt($(".sliderHolder").css("width"))*i);
} else {
$(".sliderHolder").css("width", 960);
$(".contentContainer").css("width", 960);
$(".homeSlider").css("width", 960*y)
$(".homeSlider").css("margin-left", 960*i);
}
}
$('.rightBtn a').click(function(){
if(!$('*').is(':animated')){
clearTimeout(slideTimer);
clicked = true;
if(i === -z){
$('.homeSlider').animate({
marginLeft: '-='+$(window).width()
}, function(){
$(".homeSlider").css("margin-left", -parseInt($(window).width()));
i = -1;
});
} else {
$('.homeSlider').animate({
marginLeft: '-='+$(window).width()
});
--i;
}
}
});
$('.leftBtn a').click(function(){
if(!$('*').is(':animated')){
clearTimeout(slideTimer);
clicked = true;
if(i === -1){
$('.homeSlider').animate({
marginLeft: '+='+$(window).width()
},function(){
$(".homeSlider").css("margin-left", -parseInt($(window).width())*z);
i = -z;
});
} else {
$('.homeSlider').animate({
marginLeft: '+='+$(window).width()
});
++i;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment