开发者

Issue with setInterval function - Trying to make a digital presentation webpage [closed]

Closed. This question needs debugging details. It is not currently accepting answers.

Edit the question to include desired behavior, a specific problem or error,开发者_如何学JAVA and the shortest code necessary to reproduce the problem. This will help others answer the question.

Closed 1 year ago.

Improve this question

Here is my jsfiddle document:

http://jsfiddle.net/nS9JZ/

Once you click start at the top, you can click the different li's.

A timestamp will count down in the top right of the li.

I have two issues:

1) Additional clicks to the li's will increase the rate that the timer decreases

2) The time variable is not passing correctly in the function

I do not use clearInterval because I am unsure how to use it here. I have tried to include it with no success

Any help is greatly appreciated


Whenever you process a click in $('li.item').live('click', you need to stop the previous interval timer and set a new one. This will keep the rate from increasing because you have multiple interval timers running. You will have to store the result from setInterval in an appropriately scoped isntance variable so you can call clearInterval with it on the next click before setting a new timer. This will makes sure you don't have multiple timers running at once for the same object.

In $('li.item').live('click', the variable btnclicked is not always defined which keeps the rest of the function from executing.

I don't understand your question about the time variable. Perhaps you could be more specific about which function and which piece of code or what is happening with the time variable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜