Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.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
&引用;停止“;方法isn';t在jQuery中为图像元素工作_Jquery_Html - Fatal编程技术网

&引用;停止“;方法isn';t在jQuery中为图像元素工作

&引用;停止“;方法isn';t在jQuery中为图像元素工作,jquery,html,Jquery,Html,HTML: jQuery: <img src="image/heli.png" class = "heli"> <script src="jquery/game.js" ></script> var-hel=$('.heli'); 苍蝇(); 函数fly() { 帮助设置动画({top:'-=25px',left:'+=25px'},800,CollisonCheck) } 函数CollisonCheck() { var tp=$(this).off

HTML:


jQuery:

<img src="image/heli.png"  class = "heli">

<script src="jquery/game.js" ></script>
var-hel=$('.heli');
苍蝇();
函数fly()
{
帮助设置动画({top:'-=25px',left:'+=25px'},800,CollisonCheck)
}
函数CollisonCheck()
{
var tp=$(this).offset().top;
var lft=$(this).offset().left;

如果((tp>=365)&&&(tp=241)&&(lft您的
CollisonCheck
函数将仅在动画完成后调用,因此
stop()
将不起任何作用(因为它已经停止)。您必须以某种间隔调用`

var hel = $('.heli');
fly();

function fly()
{

    hel.animate({top :'-=25px' ,left :'+=25px'},800,CollisonCheck)

}

function CollisonCheck()
{
    var tp =$(this).offset().top;
    var lft = $(this).offset().left;

    if (((tp>=365) && (tp<=610)) && ((lft>=241) && (lft<=370)))
    {
        stop_game();
    }
}

function stop_game()
{
    hel.stop();
}
函数fly()
{
帮助设置动画({top:'-=25px',left:'+=25px'},800)
设置间隔(CollisonCheck,50);
}
函数CollisonCheck()
{
var tp=hel.offset().top;
var lft=hel.offset().left;

如果((tp>=365)&&(tp=241)&&(lft我为我的代码找到了“stop”方法的替代解决方案。只需写“$fx.off=true”而不是stop()


尝试
hel.stop(true,true);
@mplungjan实际上我想在满足必要条件时停止动画。
function fly()
{
  hel.animate({top :'-=25px' ,left :'+=25px'},800)
  setInterval(CollisonCheck, 50);
}

function CollisonCheck()
{
  var tp = hel.offset().top;
  var lft = hel.offset().left;
  if (((tp>=365) && (tp<=610)) && ((lft>=241) && (lft<=370)))
  {
    stop_game();
  }
}
function stop_game()
{
$fx.off = true;
}