简体   繁体   English

通过单击事件停止元素上的双击事件

[英]Stop double click event on element with single click event

I have a JSFiddle here which lays out my problem: http://jsfiddle.net/Paddy/86YSN/7/ . 我在这里有一个JSFiddle,它解决了我的问题: http//jsfiddle.net/Paddy/86YSN/7/ It's a very simple marquee- the little white boxes simply move to the next/previous slide when clicked. 这是一个非常简单的选框 - 当点击时,小白框只需移动到下一张/上一张幻灯片。

If you double click one, things go wrong, and a slide gets stuck out of position. 如果您双击鼠标,则会出问题,并且幻灯片会卡在位置上。 I've been trying to find out how to simply disable the double click event for those elements for hours- I've tried this method: 我一直试图找出如何简单地禁用这些元素的双击事件几个小时 - 我尝试过这种方法:

$('#arrow_left').bind('dblclick',function(e){
    e.preventDefault();
});

but no luck. 但没有运气。 Can anyone help? 有人可以帮忙吗?

(Many thanks). (非常感谢)。

You could forget about the dblclick event and just stop any animations already running by adding this line 您可以忘记dblclick事件,只需通过添加此行停止已经运行的任何动画

$('.marquee_photos').stop(true,true);

into the functions called when processing the next animation. 处理下一个动画时调用的函数。 Working example -> http://jsfiddle.net/86YSN/11/ 工作示例-> http://jsfiddle.net/86YSN/11/

docs on stop() here 这里有关于stop()的文档

You should just check to see if its currently animated, if it isn't then go ahead and run your animation again. 您应该检查它当前是否已设置动画,如果不是,则继续并再次运行动画。 This allows your animation to finish, and I think is more in line with what you are wanting vs using the .stop(). 这允许你的动画完成, 我认为更符合你想要的与使用.stop()。

if(!$('.marquee_photos').is(":animated")){
   //your code here
}

JSFIDDLE HERE JSFIDDLE在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM