2017-04-25 19 views
0

タブの変更でjquery関数を停止するにはどうすればよいですか? Jquery js関数のコードを以下に示します。タブの変更でjquery js関数を停止するにはどうすればよいですか?

function move(){ 
addEventListener('load', function() { 
createProgressbar('progressbar1', '40s', function() { 
document.getElementById("close").style.display = "block"; 
document.getElementById("msg").style.display = "none"; 
}); 
}); 
} 

誰でも私を助けることができますか?必要なら他の情報のコメントをお願いします。

+0

この関数をタブでどのように呼び出すのですか? 'onclick'を通して? '最初のタブのようなもの'またはjqueryコードを通して? –

+0

[this](http://stackoverflow.com/questions/1038643/event-for-when-user-switches-browser-tabs)を参照してください。そのアンバーとsetIntervalを組み合わせてworround-around – Ninjaneer

+0

@AlivetoDieはいそれはボタンをクリックするだけで始まります。 –

答えて

0

1つのタブで、読み込み中に何らかのアクションを実行している場合(別のタブに切り替えた場合)、前回の読み込みプロセスを停止する必要がある場合は、 。

しかし、あなたが行うことができますが、あなたがタブを変更しているとすぐに表示させたくないこと(表示された負荷に関連する)hide all elementsです。

0

一般的な考え方は下記をご覧ください。

playing = function() { 
 
    foo = window.setInterval(function() { 
 
     console.log('as') 
 
    }, 500); 
 
} 
 

 
$(window).blur(function(e) { 
 
    clearInterval(foo);//clear the interval..which inturn stop execution 
 
}); 
 

 
$(window).focus(function(e) { 
 
//will get executed when current tab is focused 
 
playing() 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
注意:スニペットを実行した後に出力領域をクリックして、出力領域をクリックしてください。

関連する問題