jQuery animation: Ignore double click

后端 未结 4 1696
闹比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:25

    I normally get around this by setting a global variable and run an if like

     clicked = true;
     $(div).click(function(){
       if (!clicked){
           clicked = true;
           Your function with a callback setting clicked to false
       }
       ....
     })
    

提交回复
热议问题