1

I have added this image gallery http://tympanus.net/codrops/2011/09/20/responsive-image-gallery/ to a site I am working on. Works flawlessly, the only thing is that there is no option to autoplay the slideshow.

http://www.debellephotography.com/debelleslide/

Any help would be greatly appreciated!

4

3 回答 3

2

我在这里和那里拼凑起来,想出了一个办法,谢谢你的帮助。

var t;
var timer_is_on=0;

function timedCount()
{
$('.rg-image-nav-next').click()
t=setTimeout("timedCount()",1000);
}

function doTimer()
{
if (!timer_is_on)
{
timer_is_on=1;
timedCount(1000);
}
}

function stopCount()
{
clearTimeout(t);
timer_is_on=0;
} 

timeCount 函数每 1 秒激活下一个图像。doTimer 函数防止定时器被多次激活。stopCount 函数允许暂停幻灯片。

然后我添加了两个按钮来暂停和播放:

<div class="playbutton"><a href="javascript:doTimer();"><img src="images/play.png" width="24" height="24" alt="Play"></a></div>
<div class="pausebutton"><a href="javascript:stopCount();"><img src="images/pause.png" width="24" height="24" alt="Pause"></a></div>

您可以在此处看到它的工作原理:自动播放示例

于 2012-05-02T08:12:02.247 回答
1

您想创建一个新按钮来触发 setInterval 函数以循环播放幻灯片。它看起来像这样:

<button onclick="play()">slideshow</button>

function play() {
    setInterval(function() {
       // Do the code that triggers next image
    }, 1000);
}

数字 1000 是正在运行的函数之间的毫秒数。

于 2012-04-25T23:55:12.190 回答
1

尝试这个

var current=1;
    function autoAdv()
    {
        if(current==-1) return false;

        $('.es-carousel a').eq(current%$('.es-carousel a').length).trigger('click',[true]);    // [true] will be passed as the contentScroll parameter of the click function
        current++;
        $('.rg-image-nav-prev').eq(current%$('.rg-image-nav-prev').length).trigger('click',[true]);    // [true] will be passed as the contentScroll parameter of the click function
        current++;
    }

    // The number of seconds that the slider will auto-advance in:

    var changeEvery = 10;

    var itvl = setInterval(function(){autoAdv()},changeEvery*1000);​
于 2012-04-26T00:14:00.890 回答