我在移动页面上具有滑动功能,并且我想使用touchstart,touchend和touchmove来跟踪整个设备上的滑动功能,而不影响滚动。
这是我的代码。
jQuery('.first-frame').bind('touchmove', function(event) {
_gaq.push(['_trackEvent', 'Landing-Page', 'Swipe-Toggle-Color', '0259_2190']);
});
最佳答案
如果可以只监视jQuery Mobile中的swipeleft
和swiperight
事件,请这样做。
否则,可以在scroll
事件上设置一个全局变量,该事件将在0.2秒后重置。然后让touchmove
事件检查是否已设置该变量,如果已设置,请不要触发Google Analytics(分析)。
window.is_scrolling = false; // global variable
window.timeout_id = 0;
window.onscroll = function() {
window.is_scrolling = true;
clearTimeout(window.timeout_id);
window.timeout_id = setTimeout(function() {
window.is_scrolling = false;
}, 200); // milliseconds
};
jQuery('.first-frame').bind('touchmove', function(event) {
if (!window.is_scrolling)
_gaq.push(['_trackEvent', 'Landing-Page', 'Swipe-Toggle-Color', '0259_2190']);
});