简体   繁体   English

闪烁按钮jQuery的更好方法?

[英]Better way to blink a button jQuery?

I would like a button to blink for a short duration prior to a AJAX call (and some other animations happening). 我希望按钮在AJAX调用之前(以及其他一些正在发生的动画)闪烁一小段时间。 The ajax call happens very fast so I do not want to use AJAX's before function. Ajax调用发生得非常快,所以我不想使用AJAX的before函数。 The blink must be distinct prior to any other animations. 眨眼必须与其他动画不同。 I feel as if there is a prettier way to do this: 我觉得好像有更漂亮的方法可以做到这一点:

       //This is inside of a button click event
       $(this).addClass('active').delay(250).queue(function (e) {
            $(this).removeClass('active').delay(250).queue(function (f) {
                alert(33);
                $child.css('margin-left', $(window).width() + 10 + 'px');
                $child.load(url + 'API CALL' + $(this).data("id"), bindAClicks);
            });
        });

bindAClicks - Animates to margin:0. bindAClicks-动画到margin:0。

$child is a container div. $ child是容器div。

active is a class with a dark background. 活跃的是具有深色背景的课程。

What's wierd is that the alert is not even firing. 奇怪的是,警报甚至没有触发。

If you are referring to beforeSend, I would recommend checking out this answer which shows how to wait for your animation to finish. 如果您指的是beforeSend,我建议您查看此答案该答案显示了如何等待动画完成。

In response to Oleg's comment, I'm not sure what problem you're having when you say the response is so quick you can't see the blink. 针对Oleg的评论,我不确定当您说回复如此迅速以至于看不到眨眼时您遇到什么问题。 I created a quick example to demonstrate how it would work (so you can make the Ajax call and still perform the blink). 我创建了一个简单的示例来演示其工作方式(因此您可以进行Ajax调用并仍然执行闪烁操作)。 Hopefully this helps. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM