0
所以我有一段代码,当用户用鼠标左右滑动或触摸移动时记录日志。jQuery的鼠标悬停区域获取元素
我需要做的是停止对这个区域内的一些元素。因此,例如,该代码将记录任何挥笔在我mainContainer上
var maxTime = 1000,
// allow movement if < 1000 ms (1 sec)
maxDistance = 50,
// swipe movement of 50 pixels triggers the swipe
target = jQuery('#mainContainer'),
startX = 0,
startTime = 0,
touch = "ontouchend" in document,
startEvent = (touch) ? 'touchstart' : 'mousedown',
moveEvent = (touch) ? 'touchmove' : 'mousemove',
endEvent = (touch) ? 'touchend' : 'mouseup';
target.bind(startEvent, function(e) {
// prevent image drag (Firefox)
// e.preventDefault();
startTime = e.timeStamp;
startX = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX;
}).bind(endEvent, function(e) {
startTime = 0;
startX = 0;
}).bind(moveEvent, function(e) {
// e.preventDefault();
var currentX = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX,
currentDistance = (startX === 0) ? 0 : Math.abs(currentX - startX),
// allow if movement < 1 sec
currentTime = e.timeStamp;
if (startTime !== 0 && currentTime - startTime < maxTime && currentDistance > maxDistance) {
console.log(startEvent);
if (currentX < startX) {
// swipe left code here
console.log("swipe left");
}
if (currentX > startX) {
// swipe right code here
console.log("swipe right");
}
startTime = 0;
startX = 0;
}
});
但内mainContainer上我有一个在移动时,我不想要得到的日志几个滑块(触发条件)。
我所有的滑块都有类滑块。
我在想如果有一个if语句来说明鼠标/触摸开始的位置是否在这个类内事件没有发生。也许这是错误的做法?
如果这是一个好方法 - 我怎么知道鼠标/触摸是否在这个区域?
感谢
我来代替。是.hasClass(),但由于 – Dan 2013-02-13 01:49:43