有没有一种方法来设置html元素数组。说Section_1Section_2Section_3在所述数组内。当用户向下滚动页面时(仅向下滚动),是否可以检查用户是否按该数组中指定的节滚动?有点像...

var readerLocation = 150;
var content = ['block_1', 'block_2', 'block_3'];

bottom = $(window).height() + $(window).scrollTop();
height = $(document).height();

// If user starts to scroll send an event
if (bottom > readerLocation) {
  console.log('started reading');
  var i = 0;
  for (block in content) {
    console.log(content[i]);
    //check if scrolled past element in array here()
    i++;
  }
}

最佳答案

您可以设置$(window).scroll()事件。

对于数组中的每个元素,您都希望在页面中找到其偏移量,并将其与当前$(window).scrollTop()进行比较。每当它通过时,说offset().topSection_1,那么您就知道它在第1节中,但尚未到达第2节。

08-25 21:21
查看更多