取消绑定点击,但保留eventPreventDefault();
我正在尝试解除对动画的点击的绑定,直到动画完成,以防止发生重叠的动画。取消绑定工作正常,但是当然,然后 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以这样做:
You could do this:
为什么不从链接中删除 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.