Javascript/jQuery是否可以通过另一个函数来中断一个函数?

Javascript/jQuery是否可以通过另一个函数来中断一个函数?,javascript,jquery,recursion,fade,breakout,Javascript,Jquery,Recursion,Fade,Breakout,我正在做一个脚本,在给定的ul中旋转李的。我想知道,当其中一个li悬停时,是否有可能中断我的递归。理想情况下,无论递归是否应该继续,我都会创建一个布尔值,因为我希望在将来有一个视频嵌入到其中时将其打破。我刚刚开始,所以这基本上就是我所拥有的 HTML: CSS 还注意到,当我谈到JavaScript时,我认为自己是一个巨大的新手,我可能会以一种非常愚蠢的方式绕过这个问题,如果我不知道,任何指针都会被赏识的。干杯。我将使用鼠标上方的公共函数将类似于中止的变量设置为true,并在移动幻灯片的第一行检

我正在做一个脚本,在给定的ul中旋转李的。我想知道,当其中一个li悬停时,是否有可能中断我的递归。理想情况下,无论递归是否应该继续,我都会创建一个布尔值,因为我希望在将来有一个视频嵌入到其中时将其打破。我刚刚开始,所以这基本上就是我所拥有的

HTML:

CSS


还注意到,当我谈到JavaScript时,我认为自己是一个巨大的新手,我可能会以一种非常愚蠢的方式绕过这个问题,如果我不知道,任何指针都会被赏识的。干杯。

我将使用鼠标上方的公共函数将类似于
中止
的变量设置为true,并在
移动幻灯片的第一行检查它。如果设置为true,只需返回函数。

请原谅我的无知,如果在循环函数运行时调用函数,它不必等待?我假设当停止另一个的函数也可以在它完成时再次启动它?比方说使用悬停?它不必等待。不。是的,你可以使用函数再次启动它。@Matthew-在这种情况下,对
moveSlides()
的递归调用是最后一件事(尾部递归),因此在任何情况下,当内部调用返回时,都没有什么待处理的事情。@Stephen,“我不确定我是否理解这一点。”马修说,所以这个问题可能有助于解释它。
    <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>
    (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 );
    .rotator li
    {
 position:absolute;
 z-index:0;
 display::block !important;
 list-style-type:none;
    }
    li.current
    { 
 z-index:1 !important;
    }