【发布时间】:2014-06-20 19:49:43
【问题描述】:
我需要使用 jQuery 获取在可滚动 DIV 中完全可见的第一个元素。我很接近,但有些地方不对劲。
谁能发现问题?
$('div').on('scroll', function () {
var cutoff = $(this).scrollLeft();
$('li').removeClass('firstVisible').each(function () {
var $this = $(this);
if ($this.offset().left > cutoff) {
$this.addClass('firstVisible');
return false; // stops the iteration after the first one on the screen
}
});
console.log($('li.firstVisible').index());
});
【问题讨论】:
标签: javascript jquery horizontal-scrolling