jQuery:在水平滚动上告诉哪个元素在视口中
这个问题在这里已经有了答案:
假设#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/83341.html
上一篇: jQuery : on horizontal scroll tell which element is in viewport