1
我需要使用jQuery獲得在可滾動DIV內完全可見的第一個元素。我很接近,但有些事情是不對的。如何獲得使用jQuery進行水平滾動的元素中的第一個完全可見的元素?
任何人都可以發現問題嗎?
$('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());
});