启用动画篮子时禁用链接 [英] Disable Link while animated Basket

查看:84
本文介绍了启用动画篮子时禁用链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在此购物篮中使用此脚本: http://www.webresourcesdepot.com/fly-to-basket-effect-with-jquery/.

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

就像人们在评论中建议的那样,当您在同一张图片上多次单击时,这很容易出错.单击一次img链接后如何将其禁用,将产品添加到购物篮中时如何重新启用它?

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?

我已经尝试在函数的开头将HREF的属性设置为#,但这无济于事.

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.

在此先感谢您的帮助.

推荐答案

在onclick处理程序的开头,检查是否有繁忙标志.然后将busy标志设置为true.然后,在ajax方法的回调中,将busy标志重新设置为false.

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

这篇关于启用动画篮子时禁用链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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