为什么 jQuery 的 .preventDefault 会遮挡我的动画?
我有一个控制一些动画的锚标记,其 href 设置为 javascript:void();暂时一切正常。我将 href 更改为 # 并放置 event.preventDefault();在附加到锚标记的函数内。它阻止浏览器转到#,但现在我的动画没有发生,仅仅一秒钟后它就会显示动画的终点。我尝试将动画的持续时间延长一秒,然后我看到动画的结尾,因此就像 PreventDefault 导致第一部分出现问题一样。
知道这是怎么回事吗?这是我的代码:
$('#galleryBelt .scrollRight a').click(function(event){
slidepageCurr++;
setScrollButtons();
/* slide belt to the left */
$('#galleryBelt ul').animate({
left: '-='+slidepageWidth
}, shiftDuration);
event.preventDefault();
});
I had an anchor tag controlling some animation, with href set to javascript:void(); temporarily, and everything was working fine. I changed the href to # and put event.preventDefault(); inside the function attached to anchor tag. It's preventing the browser from going to #, but now my animation doesn't happen, just a second later it shows the end point of the animation. I tried extending the duration of the animation by a second and then I see the end of the animation, so it's like the preventDefault is causing a hiccup for that first part.
Any idea what's going on here? This is my code:
$('#galleryBelt .scrollRight a').click(function(event){
slidepageCurr++;
setScrollButtons();
/* slide belt to the left */
$('#galleryBelt ul').animate({
left: '-='+slidepageWidth
}, shiftDuration);
event.preventDefault();
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
返回 false 对这种情况有帮助吗?
Does returning false help the situation?