stopping or destroying jQuery 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.
精彩评论