仅在移动设备上激活滚动深度

Have scrollDepth only activate if on mobile device

本文关键字:激活 滚动 深度 移动      更新时间:2023-09-26

当用户滚动到页面上的特定元素时,我使用scrollDepth来触发Google分析事件,但是,我只希望在移动设备上触发它。某些元素共享桌面的相同 ID。

本质上,它

应该只在用户在移动设备上时发送滚动事件,如果他们在桌面上,它不会发送任何滚动事件。

这是我在下面组装的,但是,它似乎没有触发。思潮?

  jQuery(function() {
  jQuery.scrollDepth()
  });
  // Controls scroll-depth options
  jQuery.scrollDepth(function(e) {
  var scrollDepth = '(max-width: 600px)';
  if (window.matchMedia && window.matchMedia(scrollDepth).matches) {
  jQuery.scrollDepth({
    minHeight: 0,
    elements: ['.div1', '.div2', '.div3'],
    percentage: false,
    userTiming: false,
    pixelDepth: false,
    nonInteraction: false
  });
}
  else {
    e.preventDefault();
  }
});
var width = $(window).width();
if (width <= 600)  {
jQuery(function() {
  jQuery.scrollDepth()
  });
}
  // Controls scroll-depth options
  jQuery.scrollDepth({
    minHeight: 0,
    elements: ['.div1', '.div2', '.div3'],
    percentage: false,
    userTiming: false,
    pixelDepth: false,
    nonInteraction: false
  });