javascript - 设置每个图像在不同时间的间隔

标签 javascript jquery html slideshow setinterval

我有一个简单的 jquery 幻灯片。我需要知道如何单独更改每个图像的间隔时间

我只希望第一张图像为“9000”,其余图像为“3000”

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

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

最佳答案

只需将超时设置为 9000,然后将间隔设置为 3000:

$(function(){
    function fade() {
        $('.fadein :first-child').fadeOut(2500).next('img').fadeIn(2500).end().appendTo('.fadein');
    }
    setTimeout(function() {
        fade();
        setInterval(fade, 3000);
    }, 9000);
});

关于javascript - 设置每个图像在不同时间的间隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18024145/

相关文章:

javascript - 模拟点击DIV

Javascript - 覆盖克隆库中继承的方法

javascript - jQuery/HTML 匹配 div 的文本

javascript - Bootstrap 下拉菜单 jQuery 与其他库冲突?

html - 将表单文本字段中的值拉到 ruby​​ on rails html 中的其他位置

javascript - 如何在运行 jquery 函数后使用变量

javascript - 单击它们时如何使我的区域变暗?

jquery-ui - 如何消除 Jquery 中的冲突?

html - 在水平响应式布局中保持方形比例

javascript - jQuery 点击事件在插件中停止工作