첫 번째 함수의 코드는 특정 간격 5 초 (div1, div2, div3)에 세 개의 다른 div를 표시합니다.
div 표시를 중지하는 데 사용되는 두 번째 함수의 코드입니다.
div2를 보여 주면서 링크를 클릭하면 멈추게됩니다.
하지만 그 후에 다시 클릭하면 div1 (잘 작동 함)이 표시되지만 div3을 표시하는 다음 작업을 계속하고 싶습니다.
jquery를 사용하여 다른 함수를 토글하고 왼쪽에서 다시 시작하지 않음
JQuery와 코드 :
$(function() {
var IntervalId;
function first_function() {
var counter = 0,
divs = $('#div1,#div2,#div3');
function showDiv() {
divs.hide() // hide all divs
.filter(function (index) { return index == counter % 3; })
.show('fast'); // and show it
counter++;
};
showDiv();
IntervalId = setInterval(showDiv, 5000);
};
function second_function(){
clearInterval(IntervalId);
}
$("#link1").toggle(
first_function,second_function
);
});
html로 코드 :
<a href="javascript:void(0);" id="link1">Toggle</a>