2011-01-28 7 views
2

나는 주어진 ul에서 li의 회전 스크립트를 수행하고 있습니다. 나는 리가 망가 졌을 때 재귀를 깨는 것이 가능한지 알고 싶습니다. 이상적으로 나는 재귀가 계속되어야하는지 여부에 상관없이 부울을 만들 것입니다. 미래에 비디오가 포함될 때 휴식을 취하고 싶습니다. 나는 방금 시작 했으므로 이것이 기본적으로 내가 가진 것입니다.Javascript/jQuery 다른 함수를 통해 함수를 중단 할 수 있습니까?

HTML :

<script type="text/javascript"> 
$(document).ready(function(){ 
    $("#ulRotator").rotate(); 
}); 
    </script> 
    </head> 
    <body> 
<ul id="ulRotator" style="width:500px; height:500px;"> 
    <li style="background-color:red;"></li> 
     <li style="background-color:blue;"></li> 
     <li style="background-color:black;"></li> 
     <li style="background-color:green;"></li> 
     <li style="background-color:grey;"></li> 
    </ul> 

</body> 

자바 스크립트 :

.rotator li 
    { 
position:absolute; 
z-index:0; 
display::block !important; 
list-style-type:none; 
    } 
    li.current 
    { 
z-index:1 !important; 
    } 

는 또한 자바 스크립트에 관해서 나 자신에게 큰 초보자를 고려 있습니다

(function($){ 

var rotator; 
var rotatorLi; 

$.fn.rotate = function() { 
    rotator = this; 
    rotatorLi = rotator.children('li'); 

    rotatorLi.css('width',rotator.css('width')).css('height',rotator.css('height')); 
    rotator.addClass('rotator'); 
    $(rotatorLi[0]).addClass('current'); 

    moveSlides('right'); 
}; 


moveSlides = function(direction){ 
    var current = $(rotator).find('li.current'); 
    var currentPosition = $(rotatorLi).index(current); 
    var slideCount = $(rotatorLi).length - 1; 

    var next; 
    if (direction == 'right'){ 
    if(currentPosition == slideCount){ 
    next = rotatorLi[0]; 
    }else{  
    next = rotatorLi[currentPosition+1]; 
    } 
    } 
    else if (direction == 'left'){ 
    if(currentPosition == 0){ 
    next = rotatorLi[slideCount]; 
    }else{  
    next = rotatorLi[currentPosition-1]; 
    } 
    } 

    $(current).delay(6000).fadeOut(500,function(){ 
    $(current).removeClass('current'); 
    $(next).addClass('current'); 
    $(next).css('display','block'); 
    moveSlides(direction); 
    }); 
}; 
    })(jQuery); 

CSS, 나는 주변에 갈 수있다 이것은 나를 알지 못하는 매우 바보 같은 방식으로, 어떤 조언도 감사 할 것입니다. 건배.

답변

1

마우스 오버시 공개 함수를 사용하여 abort과 같은 변수를 true로 설정하고 첫 번째 줄의 moveSlides에서 확인하십시오. true로 설정된 경우 return이 기능에서 제외됩니다.

+0

내 기능이 무의미하기 때문에 반복 기능이 실행되는 동안 함수가 호출되면 기다릴 필요가 없습니다. 다른 함수를 중지시키는 함수가 끝나면 다시 시작할 수 있다고 가정합니다. 호버 사용을 가정 해 보겠습니다. –

+0

기다릴 필요가 없습니다. 예, 함수를 사용하여 다시 시작할 수 있습니다. – Fabian

+0

좋은 답변, 빠른 답변 주셔서 감사합니다. –