为每个图像设置不同的间隔

set different interval for each image

本文关键字:设置 图像      更新时间:2023-09-26

我想用这个简单的jquery幻灯片让一个图像暂停9秒,另一个暂停3秒

<script>
$(function(){
    $('.fadein2 img:gt(0)').hide();
    setInterval(function(){$('.fadein2 :first-child').fadeOut(2500).next('img').fadeIn(2500).end().appendTo('.fadein2');}, 9000);
});
</script>

html

<div class="fadein" > <img src="1.jpg" > <img src="2.jpg"> </div>

不确定你想做什么,但我认为你想要这个。

http://api.jquery.com/delay/

你的意思是类似于this这个2this吗?

function changeBackground() {
    $(".fadein2 img").first().fadeIn("slow", function showNext() {
        var next = $(this).next('img').length ? $(this).next('img') : $(".fadein2 img").first();
        $(this).siblings().fadeOut('slow').delay(3000);
        next.fadeIn("slow", showNext).delay(9000);
    });
}
$(function() {    //    starts when page is loaded and ready
    setTimeout(changeBackground, 0);
})

jsFiddle只使用图像,不设置为背景