Skip to content

Instantly share code, notes, and snippets.

@halfempty
Created June 4, 2012 18:54
Show Gist options
  • Save halfempty/2870170 to your computer and use it in GitHub Desktop.
Save halfempty/2870170 to your computer and use it in GitHub Desktop.
Simple jQuery Fade-in/Fade-out slideshow
<div class="slideshow">
<div>
<img src="1.jpg" alt="Image One" />
<p class="controls"><a href="#2" class="next">Next</a></p>
</div>
<div>
<img src="2.jpg" alt="Image Two" />
<p class="controls"><a href="#1" class="prev">Prev</a> /
<a href="#3" class="next">Next</a></p>
</div>
<div>
<img src="3.jpg" alt="Image Three" />
<p class="controls"><a href="#2" class="prev">Prev</a></p>
</div>
</div>
$(document).ready(function(){
// Set the initial state: Hide all but the first slide
$('.slideshow').find('> div:eq(0)').nextAll().css({'opacity':'0','display':'none'});
// On click of a controller link...
$('.controls > a').click(function(event) {
event.preventDefault();
// Get the div containing the clicked link...
var currentslide = $(this).parents('div:first');
// ... and get the index of that div
var currentposition = $('.slideshow div').index(currentslide);
// Use that index to get the slide we'll be fading to
var nextposition = ($(this).attr('class')=='next') ? currentposition+1 : currentposition-1;
// Fade the current slide out...
$('.slideshow div:eq('+currentposition+')').animate({opacity: 0}, 250, function() {
// ... and hide it.
$('.slideshow div:eq('+currentposition+')').css('display','none');
// Show the next slide...
$('.slideshow div:eq('+nextposition+')').css('display','block');
// ... and fade it in.
$('.slideshow div:eq('+nextposition+')').animate({opacity: 100}, 1500);
}
);
});
});
@hitechhitesh
Copy link

rtyrtdfvjdkjhdkfj hfdgkjdh fgkjdgh dfhd fjkgfhdg dfg

@mojtaba-ramezani
Copy link

@hitechhitesh
Are you ok?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment