【问题标题】:jQuery fadeIn fadeOut pause on hover悬停时jQuery淡入淡出暂停
【发布时间】:2010-05-04 01:04:15
【问题描述】:

我有一个小 jQuery sn-p,它将在选择间隔内淡入和淡出一组 div。我现在需要在悬停时暂停这个淡入淡出淡出,然后在鼠标移出时恢复。任何帮助表示赞赏。这是相关代码。

以下是位于我体内的东西

<div class="gcRotate">
      <div class="gcRotateContent">
         <div style="border: solid 2px black; text-align: center; width: 150px;">
            This is first content
            <img src="http://pix.motivatedphotos.com/2008/6/16/633492359109161542-Skills.jpg"
               alt="Dude" />
         </div>
      </div>
      <div class="gcRotateContent">
         <div style="border: solid 2px black; text-align: center; width: 150px">
            This is second content
            <img src="http://www.funnycorner.net/funny-pictures/5010/cheezburger-locats.jpg"
               alt="Dude" />
         </div>
      </div>
      <div class="gcRotateContent">
         <div style="border: solid 2px black; text-align: center; width: 150px">
            This is third content
            <img src="http://icanhascheezburger.files.wordpress.com/2007/06/business.jpg" alt="Dude" />
         </div>
      </div>
   </div>
   <div>
      This shouldn't move.
   </div>

   <script type="text/javascript">
      function fadeContent() {

         $(".gcRotate .gcRotateContent:hidden:first").fadeIn(500).delay(2000).fadeOut(500, function() {
         $(this).appendTo($(this).parent());

            fadeContent();
         });
      }

      $(".gcRotate").height(0);

      $(".gcRotateContent").each(
         function() {
            if ($(".gcRotate").height() < $(this).height()) {
               $(".gcRotate").height($(this).height());
            }
         }
         );

      $(".gcRotateContent").each(function() {
         $(this).css("display", "none")
      });

      fadeContent();


   </script>

【问题讨论】:

    标签: hover fadein fadeout


    【解决方案1】:

    这是我自己想出来的。

    <div class="gcRotate">
          <div class="gcRotateContent">
             <div style="border: solid 2px black; text-align: center; width: 150px;">
                This is first content
                <img src="http://pix.motivatedphotos.com/2008/6/16/633492359109161542-Skills.jpg"
                   alt="First" />
             </div>
          </div>
          <div class="gcRotateContent">
             <div style="border: solid 2px black; text-align: center; width: 150px">
                This is second content
                <img src="http://www.funnycorner.net/funny-pictures/5010/cheezburger-locats.jpg"
                   alt="Second" />
             </div>
          </div>
          <div class="gcRotateContent">
             <div style="border: solid 2px black; text-align: center; width: 150px">
                This is third content
                <img src="http://icanhascheezburger.files.wordpress.com/2007/06/business.jpg" alt="Third" />
             </div>
          </div>
       </div>
       <div>
          This shouldn't move.
       </div>
    
       <script type="text/javascript">
          function fadeContent() {
    
             $(".gcRotateContent").first().fadeOut(500, function() {
                $(".gcRotateContent:hidden:first").fadeIn(500)
             });
             $(".gcRotateContent").first().appendTo($(".gcRotateContent").parent());
          }
    
          $(".gcRotate").height(0);
    
          $(".gcRotateContent").each(
             function() {
                if ($(".gcRotate").height() < $(this).height()) {
                   $(".gcRotate").height($(this).height());
                }
             }
             );
    
          $(".gcRotateContent").each(function() {
             $(this).css("display", "none")
          });
    
          $(".gcRotate").hover(function() {window.clearInterval(timer)}, function() {timer = window.setInterval("fadeContent()", 2000)});
    
          $(".gcRotateContent").first().show(0);
          var timer = window.setInterval("fadeContent()", 2000);
    
    
       </script>
    

    【讨论】:

      猜你喜欢
      • 2013-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-16
      • 2011-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多