jQuery を使用して DOMSubtreeModified イベントをリッスンし、関数を実行しています。私が必要としているのは、イベント バーストごとに 1 回だけ関数を実行する方法です。したがって、この場合、イベントは 1 秒後にのみ実行され、3 秒後に再び実行されます。これを行う最善の方法は何ですか?
jQuery
$(function(){
setTimeout(function(){
$('#container')[0].innerHTML = 'test';
$('#container')[0].innerHTML = 'test';
$('#container')[0].innerHTML = 'test';
$('#container')[0].innerHTML = 'test';
$('#container')[0].innerHTML = 'test';
$('#container')[0].innerHTML = 'test';
},1000);
setTimeout(function(){
$('#container')[0].innerHTML = 'test';
$('#container')[0].innerHTML = 'test';
$('#container')[0].innerHTML = 'test';
$('#container')[0].innerHTML = 'test';
$('#container')[0].innerHTML = 'test';
$('#container')[0].innerHTML = 'test';
},3000);
$('#container').bind('DOMSubtreeModified',function(){
console.log('event');
functionToRun();
});
});
HTML
<div id="container"></div>
更新
setTimeout 関数は、私の問題をエミュレートするためだけに存在します。setTimeout コードを変更せずに解決策が必要です。私が抱えている問題は、DOMSubtreeModified イベントのバーストを取得することであり、バーストごとに 1 つだけ取得する必要があります。