在jQuery UI中,如何防止连续调用时运行数百万次的“脉动”效应

In jQuery UI, how to prevent the "pulsate" effect for running millions of times when called consecutively?

本文关键字:数百万 运行 效应 脉动 调用 UI jQuery 连续 何防止      更新时间:2023-09-26

我有以下代码(类似于这个):

$(Auditorium.CometService).on('bid.new', function(event, data){
    $('#feedback').text(data.msg).show('pulsate', {
        speed: 250
    });
});

问题是,对于每个"bid.new"事件,#feedback 脉动 X 次(默认值为 5),有时 2 秒内有 5 个出价,因此它会将动画排队并脉动 25 次。我需要忘记动画队列。如果在一秒钟内触发了许多"bid.new"事件,则应仅进行一次动画处理(仅脉动 5 次)。我怎样才能做到这一点?

使用 stop 方法。

$(Auditorium.CometService).on('bid.new', function(event, data){
    $('#feedback').text(data.msg).stop(true).show('pulsate', {
        speed: 250
    });
});

更新:true 参数添加到 stop() 方法中,使其删除元素的排队动画(因此,按照问题的要求运行)。