2017-04-25 1 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과 해당 anwer를 결합하십시오. – Ninjaneer

+0

@AlivetoDie 예 버튼을 클릭하면 시작됩니다. –

답변

0

하나의 탭에로드 중 일부 동작을 수행하고로드하는 동안 다른 탭으로 전환하면 이전로드 프로세스를 중지해야합니다. .

탭을 변경하자 마자 표시하지 않으려는 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>
참고 : 스 니펫을 실행 한 후 출력 영역을 클릭하여 작동 여부를 확인하십시오.

관련 문제