"停止"方法不适用于jQuery中的图像元素 [英] "stop" method isn't working for an image element in jQuery

查看:85
本文介绍了"停止"方法不适用于jQuery中的图像元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTML:

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

<script src="jquery/game.js" ></script>

jQuery:

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();
}

当我运行此代码时, stop() 方法无效。控制台也不会给出任何错误。

When I run this code, the stop() method is not working. Console also doesn't give any error.

此代码中的错误是什么?如何解决这个问题?

What is the error in this code? How to solve this problem?

推荐答案

我为我的代码找到了另一种停止方法的解决方案。只需写$ fx .off = true而不是stop()。

I found an alternative solution of "stop" method for my code.Just Write "$fx.off = true" instead of stop().

function stop_game()
{
$fx.off = true;
}

这篇关于&QUOT;停止&QUOT;方法不适用于jQuery中的图像元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆