开发者

stopping or destroying jQuery fjTimer

开发者 https://www.devze.com 2023-01-04 20:24 出处:网络
I\'m开发者_JAVA百科 using this javascript timer in jQuery: http://plugins.jquery.com/project/fjtimer

I'm开发者_JAVA百科 using this javascript timer in jQuery:

http://plugins.jquery.com/project/fjtimer

How can I stop the timer (destroy it for example)? The documentation has nothing about this issue; still if someone has an idea, please give me a hand.


You need to call timerId.stop(); to destroy the running timer.

Here is a basic example:

<html><head>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript" src="jquerytimer-min.js"></script>
<script type="text/javascript" language="javascript">
var flag = false;
$(document).ready( function() {
$.fjTimer({
    interval: 1000,
    repeat: 5,
    tick: function(counter, timerId) {
        if (flag)
            timerId.stop();
        $("#test").text($("#test").text() + "asdf");
    }
});
$('#button').click( function() {
    flag = true;
});
});
</script>
</head>
<body>
<div id='test'></div>
<input id='button' type='button' value='die' />
</body>
</html>

The timer just adds "asdf" to the div every interval, when you click "die" it will set a flag that on the next interval the timer should stop.

0

精彩评论

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