我正在用jQuery製作幻燈片。幻燈片放映全部一次
下面是代碼:
$(function() {
var slides = $(".slide-img");
slides.eq(0).fadeIn(600); // initialize first slide
$(".btn-container button:eq(0)").addClass('active'); // add active class to button
$(".btn-container button").click(function() {
$(".btn-container button").removeClass('active');
$(this).addClass('active');
var imgCode = $(this).attr('data-slide');
$(".slide-container img").fadeOut(600);
$(".slide-container img").eq(imgCode).delay(600).fadeIn(600);
var title = $(".slide-container img").eq(imgCode).attr('data-title');
$(".slide-container .title .text").hide().text(title).delay(500).fadeIn(800);
});
var timeout = function() {
$(".btn-container button").stop().each(function() {
$(this).click();
}).stop();
}
window.setInterval(timeout, 3000);
});
<div class="wrapper">
<div class="slide-container container">
<div class="slide">
<img src="http://static2.businessinsider.com/image/4e15d75ccadcbb1349070000/ukraine-may-face-8-billion-in-losses-from-hosting-a-soccer-tournament.jpg" class="slide-img" data-title="GOAL!" />
<img src="http://static6.businessinsider.com/image/4cf64ef84bd7c8ae78160000/italian-soccer-serie-a-italy.jpg" class="slide-img" data-title="Italian Soccer" />
<img src="http://static5.businessinsider.com/image/4dc7f45249e2ae2a272a0000/there-are-only-7-people-who-make-1000000-playing-soccer-in-mls.jpg" class="slide-img" data-title="Landon Donovan" />
<span class="title"><span class="text">GOAL!</span></span>
</div>
</div>
<div class="btn-container container">
<button class="control" data-slide="0">•</button>
<button class="control" data-slide="1">•</button>
<button class="control" data-slide="2">•</button>
</div>
</div>
這應該更改與setInterval()
顯示的圖像。但是,所有的圖像同時出現會發生什麼。我該如何讓他們淡入淡出?
這隻能運行一次。我希望幻燈片繼續無限廣告。 – TricksfortheWeb
完成...希望它有助於.. –