我定义了几个函数。setInterval 每秒随机选择一个。如何临时清除间隔以暂停此行为?
演示:http: //jsfiddle.net/kthornbloom/NtVBZ/1/
代码:function playZoomout() { $('.debug').append('1'); }
function playZoomin() {
$('.debug').append('2');
}
function playPanright() {
$('.debug').append('3');
}
function playPanleft() {
$('.debug').append('4');
}
var fns = [playZoomout, playZoomin, playPanright, playPanleft]
setInterval(function () {
fns[Math.floor(Math.random() * fns.length)]();
}, 1000);
// This isn't working. Probably because the interval above isn't really named?
$('.pause').hover(function(ev){
clearInterval(fns);
}, function(ev){
timer = setInterval( fns, 1000);
});