jQuery动画:忽略双击 [英] jQuery animation: Ignore double click

查看:114
本文介绍了jQuery动画:忽略双击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的jQuery动画,在.click()事件后向右或向左移动div。

I have a simple jQuery animation that moves a div to the right or left, upon a .click() event.

但是,如果用户点击事件

However, if the user clicks the event twice, it fires twice, which messes up the formatting.

这里是我有一个例子:

$('a#right').click( function () {

if ($(this).is(':visible')) {

    $('#slide').animate({right: '+=257'}, 400, function () {
    slide_button();
    });

    }
});

函数slide_button()会检查div的位置是否在用户的观点。如果是,它将允许右或左按钮可见。如果超出限制,它将隐藏按钮。

The function slide_button() will check to see if the position of the div is within acceptable limits for the user's viewpoint. If so, it will allow the right or left button to be visible. If it is outside of the limits, it will hide the buttons.

它工作得很好,除非我单击它两次 - 然后它会刚刚滑过页面。

It works well, except if I click it twice--then it will just slide right off the page.

是否有办法忽略双击?

推荐答案

只要检查元素是否已经在动画:

Just check if element is already animating:

$('a#right').click( function () {
    if ($(this).is(':visible') && !$('#slide').is(':animated')) {
        $('#slide').animate({right: '+=257'}, 400, function () {
            slide_button();
        });
    }
});    

这篇关于jQuery动画:忽略双击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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