[英]JQuery - mousedown,mouseup and click on same element
I have a carousel and I need to make him work as Instagram carousel does. 我有一个轮播,我需要让他像Instagram轮播一样工作。 On click change slide, but on mousedown just stop animation.
在单击更改幻灯片时,但在鼠标按下时停止动画。 My JQuery :
我的jQuery:
$(".fancy-carousel").on('mousedown',function (e) {
...stop animation
});
$(".fancy-carousel").on('mouseup',function (e) {
..continue animation
});
$(".fancy-carousel").on('click',function (e) {
..change slide
});
But i don´t know how can i let script know about difference between "click" and "mousedown". 但是我不知道如何让脚本知道“ click”和“ mousedown”之间的区别。 When i click on element and hold for a time, it stop animation but after "mouseup" it trigger "click" event too.
当我单击元素并保持一段时间时,它会停止动画,但在“鼠标”操作后也会触发“点击”事件。 Is there any way how to split this events?
有什么办法可以拆分此事件? Or should i do it with some calculating of mouse hold time?
还是应该通过一些鼠标保持时间来计算?
A “click” is just a full cycle of a “mousedown” and a “mouseup”. “点击”只是“鼠标按下”和“鼠标向上”的整个周期。 You can't have one without the other.
你不能没有一个。
For your code to know the difference, you'll need a variable that tracks your intentions. 为了让您的代码了解不同之处,您需要一个变量来跟踪您的意图。
var intention = "click";
var detectIntention = setTimeout(function(){
intention = "mouseup";
})
clearTimeout(detectIntention);
if (intention === "mouseup") {
// do mouseup stuff
}
// reset intention
intention = click;
if (intention === "click") {
// do click stuff
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.