2

指定された ul で li をローテーションするスクリプトを実行しています。liの1つがホバリングされているときに、再帰を中断できるかどうかを知りたいです。理想的には、再帰を継続するかどうかに関係なくブール値を作成します。これは、将来ビデオを埋め込むときにこれを壊したいからです。始めたばかりなので基本的にはこんな感じです。

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>

Javascript:

    (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

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

また、Javascriptに関しては、私は自分自身を非常に初心者だと考えていることに注意してください。私は、知らないうちに非常にばかげた方法でこれを回避している可能性があります。乾杯。

4

1 に答える 1

1

abortマウスオーバーで public 関数を使用して変数 like を true に設定し、 の最初の行で確認しmoveSlidesます。true に設定されている場合は、単にreturn関数の外に出ます。

于 2011-01-28T20:35:47.957 に答える