jQuery : on horizontal scroll tell which element is in viewport

This question already has an answer here:

  • Check if element is visible after scrolling 38 answers

  • 假设#stickers拥有正确的CSS来进行溢出滚动(如果没有,您的滚动处理程序将永远不会触发。)

    var scrollingIsThrottled = false;
    var sticker = $(".sticker");
    $("#stickers").scroll(function() {
      var stickers_width = $(this).width();
      if (!scrollingIsThrottled) {
        scrollingIsThrottled = true;
    
        var StickerMatchingExpression = sticker.filter(function() {
          var $this = $(this);
          var left_of_element = $this.offset().left;
          var right_of_element = left_of_element + $this.width();
          return 0 <= left_of_element && right_of_element <= stickers_width;
        });
        scrollingIsThrottled = false;
      }
    });
    
    链接地址: http://www.djcxy.com/p/83342.html

    上一篇: Javascript:如何检测浏览器窗口是否滚动到底部?

    下一篇: jQuery:在水平滚动上告诉哪个元素在视口中