取消绑定,但保留eventPreventDefault(); [英] unbind click, but keep eventPreventDefault();

查看:134
本文介绍了取消绑定,但保留eventPreventDefault();的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我们取消对动画的单击,直到动画结束为止,以防止发生重叠的动画.取消绑定工作正常,但当然,然后event.preventDefault停止工作,并且我的按钮/链接再次变为活动状态.我不确定该如何解决.

I'm trying to us unbind a click on an animation until the animation finishes to keep overlapping animiations from happening. The unbind works fine, but of course, then the event.preventDefault stops working and my button/link becomes active again. I'm not sure how to work my way around this.

该代码的缩短版是:

$('a.Next').bind('click', SlideFwd);
function SlideFwd(e){
    e.preventDefault();
    $('a.Next').unbind();
    $('ul.GridviewList').animate({
        left: '-=800px'
        }, 'slow', function() {
        $('a.Next').bind('click', SlideFwd);    
    });
};

并且html是:

<div>

    <div class="SlideControl">
        <p class="Pages"><span class="ProdCountDisplay">#</span> of <span class="ProdCountTotal">10</span></p>
        <ul>
            <li><a class="Disabled button_Back Previous" href="#">Prev</a></li>
            <li><a class="button_Next Next" href="#">Next</a></li>
        </ul>
    </div>
    <ul class="GridviewList">
        <li class="ProdWrap">This is a slider space 1</li>
        <li class="ProdWrap"> This is a slider space 2</li>
        <li class="ProdWrap"> This is a slider space 3</li>
        <li class="ProdWrap"> This is a slider space 4</li>
        <li class="ProdWrap"> This is a slider space 5 </li>
        <li class="ProdWrap">This is a slider space 6 </li>
        <li class="ProdWrap"> This is a slider space 7</li>
        <li class="ProdWrap"> This is a slider space 8 </li>
        <li class="ProdWrap"> This is a slider space 9 </li>
        <li class="ProdWrap"> This is a slider space 10 </li>
    </ul> <!-- ul.Gridviewlist -->
</div> 

完整的工作版本在这里: http://iwrb.idleprattle.com/Slider.htm (现在只有下一个已设置取消绑定/绑定)

A complete working version is here: http://iwrb.idleprattle.com/Slider.htm (only the next has the unbind/bind set up now)

我也尝试了将preventDefault放在函数SlideFwd之外,但是它也必须取消绑定. I.E.

I also tried taking the preventDefault outside the function SlideFwd, but it must unbind that too. I.E.

$('a.Next').click(function(){e.preventDefault();});

推荐答案

您可以执行以下操作:

$('a.Next').bind('click', SlideFwd);

...

$('a.Next').unbind().bind('click',function(e){e.preventDefault();});

...

$('a.Next').unbind().bind('click', SlideFwd);

这篇关于取消绑定,但保留eventPreventDefault();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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