Disable Link while animated Basket

笑着哭i 提交于 2019-12-11 07:53:30

问题


I'm using this script for my online shopping basket: http://www.webresourcesdepot.com/fly-to-basket-effect-with-jquery/.

Like people suggest in the comments it's easy buggy when you click multiple times on the same image. How can I disable the img link when it's clicked once and re-enable it when the product is added to the basket?

I've tried setting the attribute HREF of to # in the beginning of the function, but that doesn't help.

So when a user clicks the function needs to be executed, but the link should be disabled as long as the function is busy.

thanks in advance for your help.


回答1:


At the begining of the onclick handler, check for a busy flag. Then set the busy flag to true. Then, in the callback for the ajax method, set the busy flag back to false.

var busy = false;

$('#myLink').click(function(e){
    if(busy) {
        e.preventDefault();
        return;
    }

    busy = true;
    //make ajax call

    $.ajax {..., function(){
        //in ajax callback
        busy = false;
    }}
});


来源:https://stackoverflow.com/questions/3064886/disable-link-while-animated-basket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!