jQuery animation: Ignore double click

后端 未结 4 1675
闹比i
闹比i 2021-01-05 03:51

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 mes

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-05 04:32

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

提交回复
热议问题