Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 停止动画jQ_Javascript_Jquery - Fatal编程技术网

Javascript 停止动画jQ

Javascript 停止动画jQ,javascript,jquery,Javascript,Jquery,我遇到了一个问题,我不知道如何用mouseover停止我的函数,用mouseout重新启动它 <script type="text/javascript"> function fadeEngine(x) { var total_divs=3; //setze hier die nummer der gewollten divs var y=x; if(x==total_divs) y=1; e

我遇到了一个问题,我不知道如何用mouseover停止我的函数,用mouseout重新启动它

  <script type="text/javascript">

  function fadeEngine(x) {

  var total_divs=3; //setze hier die nummer der gewollten divs

                  var y=x;

                  if(x==total_divs) y=1; else y++;

                  $("#fade"+x).css("display","none");

                  $("#fade"+y).fadeIn("slow");

                  setTimeout('fadeEngine('+y+')',3000); //modifi alle 3000 miliseconds nen neuen div
          }

        fadeEngine(0); //Initialisation des Scripts

  </script>

<script type="text/javascript">
$(document).ready(function(){
/*
    $("#container").hover(function(){
            stop('mouse over');
    },function(){
            alert('mouse out');
    });
*/
/*
$("#container").hover(function()
   {
      $(this).stop().fadeTo("slow", 1.00);
   },
   function()
   {
      $(this).stop().fadeTo("fast", 0.50);
   });
*/



});

</script>
</head>
<body>

<div id="container" style="width:200px;height:200px;background:#afafaf;color:#red;">

    <div id="fade1">Content  one</div>
    <div id="fade2" style="display:none">Content  two</div>
    <div id="fade3" style="display:none">Content three</div>
</div>
    <div class="blocker">&nbsp;</div>
</body>
</html>
首先,这里是我的测试代码:

  <script type="text/javascript">

  function fadeEngine(x) {

  var total_divs=3; //setze hier die nummer der gewollten divs

                  var y=x;

                  if(x==total_divs) y=1; else y++;

                  $("#fade"+x).css("display","none");

                  $("#fade"+y).fadeIn("slow");

                  setTimeout('fadeEngine('+y+')',3000); //modifi alle 3000 miliseconds nen neuen div
          }

        fadeEngine(0); //Initialisation des Scripts

  </script>

<script type="text/javascript">
$(document).ready(function(){
/*
    $("#container").hover(function(){
            stop('mouse over');
    },function(){
            alert('mouse out');
    });
*/
/*
$("#container").hover(function()
   {
      $(this).stop().fadeTo("slow", 1.00);
   },
   function()
   {
      $(this).stop().fadeTo("fast", 0.50);
   });
*/



});

</script>
</head>
<body>

<div id="container" style="width:200px;height:200px;background:#afafaf;color:#red;">

    <div id="fade1">Content  one</div>
    <div id="fade2" style="display:none">Content  two</div>
    <div id="fade3" style="display:none">Content three</div>
</div>
    <div class="blocker">&nbsp;</div>
</body>
</html>

  <script type="text/javascript">

  function fadeEngine(x) {

  var total_divs=3; //setze hier die nummer der gewollten divs

                  var y=x;

                  if(x==total_divs) y=1; else y++;

                  $("#fade"+x).css("display","none");

                  $("#fade"+y).fadeIn("slow");

                  setTimeout('fadeEngine('+y+')',3000); //modifi alle 3000 miliseconds nen neuen div
          }

        fadeEngine(0); //Initialisation des Scripts

  </script>

<script type="text/javascript">
$(document).ready(function(){
/*
    $("#container").hover(function(){
            stop('mouse over');
    },function(){
            alert('mouse out');
    });
*/
/*
$("#container").hover(function()
   {
      $(this).stop().fadeTo("slow", 1.00);
   },
   function()
   {
      $(this).stop().fadeTo("fast", 0.50);
   });
*/



});

</script>
</head>
<body>

<div id="container" style="width:200px;height:200px;background:#afafaf;color:#red;">

    <div id="fade1">Content  one</div>
    <div id="fade2" style="display:none">Content  two</div>
    <div id="fade3" style="display:none">Content three</div>
</div>
    <div class="blocker">&nbsp;</div>
</body>
</html>

功能fadeEngine(x){
var total_divs=3;//设置gewollten divs中的数字
变量y=x;
如果(x==total_divs)y=1;否则y++;
$(“#淡入”+x).css(“显示”、“无”);
$(#fade“+y).fadeIn(“慢”);
setTimeout('fadeEngine('+y+'),3000);//修改所有3000毫秒的新分区
}
fadeEngine(0)//初始化des脚本
$(文档).ready(函数(){
/*
$(“#容器”).hover(函数(){
停止(“鼠标悬停”);
},函数(){
警惕(“鼠标悬停”);
});
*/
/*
$(“#容器”).hover(函数()
{
$(this).stop().fadeTo(“slow”,1.00);
},
函数()
{
$(this).stop().fadeTo(“fast”,0.50);
});
*/
});
内容一
内容二
内容三
如果我跳过contentdiv,我如何停止我的函数fadeEngine,如果我移出该div,如何启动它

  <script type="text/javascript">

  function fadeEngine(x) {

  var total_divs=3; //setze hier die nummer der gewollten divs

                  var y=x;

                  if(x==total_divs) y=1; else y++;

                  $("#fade"+x).css("display","none");

                  $("#fade"+y).fadeIn("slow");

                  setTimeout('fadeEngine('+y+')',3000); //modifi alle 3000 miliseconds nen neuen div
          }

        fadeEngine(0); //Initialisation des Scripts

  </script>

<script type="text/javascript">
$(document).ready(function(){
/*
    $("#container").hover(function(){
            stop('mouse over');
    },function(){
            alert('mouse out');
    });
*/
/*
$("#container").hover(function()
   {
      $(this).stop().fadeTo("slow", 1.00);
   },
   function()
   {
      $(this).stop().fadeTo("fast", 0.50);
   });
*/



});

</script>
</head>
<body>

<div id="container" style="width:200px;height:200px;background:#afafaf;color:#red;">

    <div id="fade1">Content  one</div>
    <div id="fade2" style="display:none">Content  two</div>
    <div id="fade3" style="display:none">Content three</div>
</div>
    <div class="blocker">&nbsp;</div>
</body>
</html>

非常感谢您的帮助

对于fadeEngine中的fadeIn和fadeOut效果,我不确定您希望发生什么,但是,我可以给您两条建议:

  <script type="text/javascript">

  function fadeEngine(x) {

  var total_divs=3; //setze hier die nummer der gewollten divs

                  var y=x;

                  if(x==total_divs) y=1; else y++;

                  $("#fade"+x).css("display","none");

                  $("#fade"+y).fadeIn("slow");

                  setTimeout('fadeEngine('+y+')',3000); //modifi alle 3000 miliseconds nen neuen div
          }

        fadeEngine(0); //Initialisation des Scripts

  </script>

<script type="text/javascript">
$(document).ready(function(){
/*
    $("#container").hover(function(){
            stop('mouse over');
    },function(){
            alert('mouse out');
    });
*/
/*
$("#container").hover(function()
   {
      $(this).stop().fadeTo("slow", 1.00);
   },
   function()
   {
      $(this).stop().fadeTo("fast", 0.50);
   });
*/



});

</script>
</head>
<body>

<div id="container" style="width:200px;height:200px;background:#afafaf;color:#red;">

    <div id="fade1">Content  one</div>
    <div id="fade2" style="display:none">Content  two</div>
    <div id="fade3" style="display:none">Content three</div>
</div>
    <div class="blocker">&nbsp;</div>
</body>
</html>
可以使用jQuery效果
stop()
停止选定元素上的所有当前jQuery动画。例如:

  <script type="text/javascript">

  function fadeEngine(x) {

  var total_divs=3; //setze hier die nummer der gewollten divs

                  var y=x;

                  if(x==total_divs) y=1; else y++;

                  $("#fade"+x).css("display","none");

                  $("#fade"+y).fadeIn("slow");

                  setTimeout('fadeEngine('+y+')',3000); //modifi alle 3000 miliseconds nen neuen div
          }

        fadeEngine(0); //Initialisation des Scripts

  </script>

<script type="text/javascript">
$(document).ready(function(){
/*
    $("#container").hover(function(){
            stop('mouse over');
    },function(){
            alert('mouse out');
    });
*/
/*
$("#container").hover(function()
   {
      $(this).stop().fadeTo("slow", 1.00);
   },
   function()
   {
      $(this).stop().fadeTo("fast", 0.50);
   });
*/



});

</script>
</head>
<body>

<div id="container" style="width:200px;height:200px;background:#afafaf;color:#red;">

    <div id="fade1">Content  one</div>
    <div id="fade2" style="display:none">Content  two</div>
    <div id="fade3" style="display:none">Content three</div>
</div>
    <div class="blocker">&nbsp;</div>
</body>
</html>
$("#fade"+y).stop();
var timeout = setTimeout('fadeEngine('+y+')',3000);
// later...
clearTimeout(timeout);
将停止该元素当前状态下的淡入淡出动画。如果愿意,您可以重置CSS

  <script type="text/javascript">

  function fadeEngine(x) {

  var total_divs=3; //setze hier die nummer der gewollten divs

                  var y=x;

                  if(x==total_divs) y=1; else y++;

                  $("#fade"+x).css("display","none");

                  $("#fade"+y).fadeIn("slow");

                  setTimeout('fadeEngine('+y+')',3000); //modifi alle 3000 miliseconds nen neuen div
          }

        fadeEngine(0); //Initialisation des Scripts

  </script>

<script type="text/javascript">
$(document).ready(function(){
/*
    $("#container").hover(function(){
            stop('mouse over');
    },function(){
            alert('mouse out');
    });
*/
/*
$("#container").hover(function()
   {
      $(this).stop().fadeTo("slow", 1.00);
   },
   function()
   {
      $(this).stop().fadeTo("fast", 0.50);
   });
*/



});

</script>
</head>
<body>

<div id="container" style="width:200px;height:200px;background:#afafaf;color:#red;">

    <div id="fade1">Content  one</div>
    <div id="fade2" style="display:none">Content  two</div>
    <div id="fade3" style="display:none">Content three</div>
</div>
    <div class="blocker">&nbsp;</div>
</body>
</html>
若要停止调用先前使用
setTimeout
排队的函数,必须获取返回值并调用
clearTimeout()
。例如:

  <script type="text/javascript">

  function fadeEngine(x) {

  var total_divs=3; //setze hier die nummer der gewollten divs

                  var y=x;

                  if(x==total_divs) y=1; else y++;

                  $("#fade"+x).css("display","none");

                  $("#fade"+y).fadeIn("slow");

                  setTimeout('fadeEngine('+y+')',3000); //modifi alle 3000 miliseconds nen neuen div
          }

        fadeEngine(0); //Initialisation des Scripts

  </script>

<script type="text/javascript">
$(document).ready(function(){
/*
    $("#container").hover(function(){
            stop('mouse over');
    },function(){
            alert('mouse out');
    });
*/
/*
$("#container").hover(function()
   {
      $(this).stop().fadeTo("slow", 1.00);
   },
   function()
   {
      $(this).stop().fadeTo("fast", 0.50);
   });
*/



});

</script>
</head>
<body>

<div id="container" style="width:200px;height:200px;background:#afafaf;color:#red;">

    <div id="fade1">Content  one</div>
    <div id="fade2" style="display:none">Content  two</div>
    <div id="fade3" style="display:none">Content three</div>
</div>
    <div class="blocker">&nbsp;</div>
</body>
</html>
$("#fade"+y).stop();
var timeout = setTimeout('fadeEngine('+y+')',3000);
// later...
clearTimeout(timeout);

这将清除挂起的超时事件并防止其发生。

如果只是将动画附加到bevahiour等上的鼠标,请尝试以下操作:

  <script type="text/javascript">

  function fadeEngine(x) {

  var total_divs=3; //setze hier die nummer der gewollten divs

                  var y=x;

                  if(x==total_divs) y=1; else y++;

                  $("#fade"+x).css("display","none");

                  $("#fade"+y).fadeIn("slow");

                  setTimeout('fadeEngine('+y+')',3000); //modifi alle 3000 miliseconds nen neuen div
          }

        fadeEngine(0); //Initialisation des Scripts

  </script>

<script type="text/javascript">
$(document).ready(function(){
/*
    $("#container").hover(function(){
            stop('mouse over');
    },function(){
            alert('mouse out');
    });
*/
/*
$("#container").hover(function()
   {
      $(this).stop().fadeTo("slow", 1.00);
   },
   function()
   {
      $(this).stop().fadeTo("fast", 0.50);
   });
*/



});

</script>
</head>
<body>

<div id="container" style="width:200px;height:200px;background:#afafaf;color:#red;">

    <div id="fade1">Content  one</div>
    <div id="fade2" style="display:none">Content  two</div>
    <div id="fade3" style="display:none">Content three</div>
</div>
    <div class="blocker">&nbsp;</div>
</body>
</html>
$(this).mouseover(function () {

    // stops the hide event if we move from the trigger to the popup element
    if (hideDelayTimer) clearTimeout(hideDelayTimer);

    // don't trigger the animation again if we're being shown, or already visible
    if (beingShown || shown) {
      return;
    } else {
      beingShown = true;

      // (we're using chaining) now animate
      this.animate({
        //some animation stuff
      }, function() {
      // once the animation is complete, set the tracker variables
        beingShown = false;
        shown = true;
      });
    }
}).mouseout(function () {

    // reset the timer if we get fired again - avoids double animations
    if (hideDelayTimer) clearTimeout(hideDelayTimer);

     // store the timer so that it can be cleared in the mouseover if required
    hideDelayTimer = setTimeout(function () {
      hideDelayTimer = null;
      this.animate({
         //some animation stuff
      }, function () {
      // once the animate is complete, set the tracker variables
        shown = false;
         });
      }, hideDelay);
});
为所有的
#fade
X元素设置一个类(例如.faders),然后使用:

  <script type="text/javascript">

  function fadeEngine(x) {

  var total_divs=3; //setze hier die nummer der gewollten divs

                  var y=x;

                  if(x==total_divs) y=1; else y++;

                  $("#fade"+x).css("display","none");

                  $("#fade"+y).fadeIn("slow");

                  setTimeout('fadeEngine('+y+')',3000); //modifi alle 3000 miliseconds nen neuen div
          }

        fadeEngine(0); //Initialisation des Scripts

  </script>

<script type="text/javascript">
$(document).ready(function(){
/*
    $("#container").hover(function(){
            stop('mouse over');
    },function(){
            alert('mouse out');
    });
*/
/*
$("#container").hover(function()
   {
      $(this).stop().fadeTo("slow", 1.00);
   },
   function()
   {
      $(this).stop().fadeTo("fast", 0.50);
   });
*/



});

</script>
</head>
<body>

<div id="container" style="width:200px;height:200px;background:#afafaf;color:#red;">

    <div id="fade1">Content  one</div>
    <div id="fade2" style="display:none">Content  two</div>
    <div id="fade3" style="display:none">Content three</div>
</div>
    <div class="blocker">&nbsp;</div>
</body>
</html>
$('.faders').stop();
或者给container div一个id,比如
#faderbox
,然后说:

  <script type="text/javascript">

  function fadeEngine(x) {

  var total_divs=3; //setze hier die nummer der gewollten divs

                  var y=x;

                  if(x==total_divs) y=1; else y++;

                  $("#fade"+x).css("display","none");

                  $("#fade"+y).fadeIn("slow");

                  setTimeout('fadeEngine('+y+')',3000); //modifi alle 3000 miliseconds nen neuen div
          }

        fadeEngine(0); //Initialisation des Scripts

  </script>

<script type="text/javascript">
$(document).ready(function(){
/*
    $("#container").hover(function(){
            stop('mouse over');
    },function(){
            alert('mouse out');
    });
*/
/*
$("#container").hover(function()
   {
      $(this).stop().fadeTo("slow", 1.00);
   },
   function()
   {
      $(this).stop().fadeTo("fast", 0.50);
   });
*/



});

</script>
</head>
<body>

<div id="container" style="width:200px;height:200px;background:#afafaf;color:#red;">

    <div id="fade1">Content  one</div>
    <div id="fade2" style="display:none">Content  two</div>
    <div id="fade3" style="display:none">Content three</div>
</div>
    <div class="blocker">&nbsp;</div>
</body>
</html>
$('#faderbox div').stop();

尝试将停止行为应用于需要它的每个元素,例如

  <script type="text/javascript">

  function fadeEngine(x) {

  var total_divs=3; //setze hier die nummer der gewollten divs

                  var y=x;

                  if(x==total_divs) y=1; else y++;

                  $("#fade"+x).css("display","none");

                  $("#fade"+y).fadeIn("slow");

                  setTimeout('fadeEngine('+y+')',3000); //modifi alle 3000 miliseconds nen neuen div
          }

        fadeEngine(0); //Initialisation des Scripts

  </script>

<script type="text/javascript">
$(document).ready(function(){
/*
    $("#container").hover(function(){
            stop('mouse over');
    },function(){
            alert('mouse out');
    });
*/
/*
$("#container").hover(function()
   {
      $(this).stop().fadeTo("slow", 1.00);
   },
   function()
   {
      $(this).stop().fadeTo("fast", 0.50);
   });
*/



});

</script>
</head>
<body>

<div id="container" style="width:200px;height:200px;background:#afafaf;color:#red;">

    <div id="fade1">Content  one</div>
    <div id="fade2" style="display:none">Content  two</div>
    <div id="fade3" style="display:none">Content three</div>
</div>
    <div class="blocker">&nbsp;</div>
</body>
</html>
$('.faders').each(function () {
  $(this).mouseover(function () {
    $(this).stop(); 
  });
});