1

我在悬停图像上使用它:

$('.img-style').hover (function(e) {
    var prixPlus = $(this).closest('a').attr('data-prix'); 
    prixPlus = parseFloat(prixPlus);
    var prixNew = prix + prixPlus;

    $('#chgePrix').html(prixNew.toFixed(2));
    $('#txtapart').fadeTo('fast', 0.1);
}, function(e) {
    $('#chgePrix').html(prix.toFixed(2));
    $('#txtapart').fadeTo('fast', 1);
});

但是,如果我在图像上快速通过鼠标 2 次或更多次,$('#txtapart') 淡入淡出 2 次或更多次!如何停止淡入淡出传播?

谢谢你的帮助...

4

2 回答 2

2

使用stop()方法

 $('#txtapart').stop(true,true).fadeTo('fast', 0.1);

这会强制之前的动画结束。这两个true参数清除队列并在其终点设置动画,以便在触发其他事件时新动画可以立即开始。

http://api.jquery.com/stop/

于 2012-06-19T15:15:42.267 回答
0

每次鼠标悬停时都会调用该函数。没有很好的方法来检测一个函数是否已经在 J​​avascript 中运行。

于 2012-06-19T15:13:00.553 回答