取消绑定点击,但保留eventPreventDefault();

发布于 2024-11-04 07:37:14 字数 2014 浏览 3 评论 0原文

我正在尝试解除对动画的点击的绑定,直到动画完成,以防止发生重叠的动画。取消绑定工作正常,但是当然,然后 event.preventDefault 停止工作,我的按钮/链接再次变为活动状态。我不知道如何解决这个问题。

代码的缩短版本是:

$('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 (现在只有下一个设置了取消绑定/绑定)

我还尝试在函数 SlideFwd 之外使用 PreventDefault,但它也必须取消绑定。 IE

$('a.Next').click(function(){e.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.

Shortened version of the code is:

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

and the html is:

<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> 

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

脱离于你 2024-11-11 07:37:14

你可以这样做:

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

...

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

...

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

You could do this:

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

...

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

...

$('a.Next').unbind().bind('click', SlideFwd);
慢慢从新开始 2024-11-11 07:37:14

为什么不从链接中删除 href 属性。它在那里没有用处,可以通过 CSS 设置光标,如果 a 元素没有 href,如果没有附加事件处理程序,则没有什么可以阻止的。

Why not removing the href-attribute from the link. It makes no use there, a cursor can be set via CSS, and if an a-element has no href, there's nothing to prevent from if no event-handler is attached.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文