English 中文(简体)
页: 1 薪酬安排
原标题:jQuery setInterval & setTimeout

I m having a slight issue with my jQuery code. I ve basically got a timer that loops through a set of images, which is on a setInterval

当我点击右边或左边控制器时,它停止了以用户点击而不是自动点击的间隔和磨损图像。

$( a.right ).click(function () {

    clearInterval(myInterval);
    setTimeout(function () { slideshow(); }, 9000);

    if (count < max - 1) {
        $( div.feature-image ).eq(count).fadeOut( 1000 , function () {

            count++;
            $( div.feature-image ).eq(count).fadeIn( 1000 );
            info++;
            $( div.img-info ).html(info +   of   + max +   |  );


        })

    }

I ve used a setTimeout to wait 4seconds then continue the loop cycle. Although I don t think it s the most elegant way to do it because the Jquery doesn t know to stop the if statement. Is there a way I can on the setTimeout stop the if statement from carrying on it s function?

最佳回答

并非我完全理解这个问题,而是这样的东西。

setTimeout(function () {
  setTimeoutTriggered = true;
  slideshow();
}, 9000);

if ( (count < max - 1) && !setTimeoutTriggered ) {
  ...
}

Of course you can give setTimeoutTriggered a more semantic name. And would be better to avoid global variables :)

Anyway, I find this jQuery plugin really good to manage timeouts and intervals! http://plugins.jquery.com/project/timers

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签