I want to make a basic fadein fadeout slideshow.I only make it auto run once. How to make it have a loop??
html
<img src="image1.jpg" class="img1">
<img src="image2.jpg" class="img2">
js
$(document).ready(function () {
function playslider(){
$('.img1').fadeIn(800).delay(800).fadeOut(800);
$('.img2').delay(1600).fadeIn(800).delay(800).fadeOut(800);
}
playslider();
});
Try changing it to this:
$(document).ready(function () {
function playslider(){
$('.img1').fadeIn(800).delay(800).fadeOut(800);
$('.img2').delay(1600).fadeIn(800).delay(800).fadeOut(800, playslider);
//^callback function
}
playslider();
});
This is called a "callback function". The idea is that it gets called when your last fadeout completes. You can read more here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With