I am creating a self scrolling, auto updating table and need to search through through elements of a class from a certain point. My code currently is this:
var nextScroll;
setInterval(function() {
if ($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
$('.seen').removeClass('seen');
$('html, body').animate({
scrollTop: 0
}, 2000);
} else {
$('.job-item:not(.seen)').each(function() {
var visible = $(this).visible();
if (!visible) {
nextScroll = $(this).offset().top;
$(this).addClass("current-scroll");
return false;
} else {
$(this).addClass('seen');
}
});
$('html, body').animate({
scrollTop: nextScroll
}, 2000);
}
}, 7000);
setInterval(function() {
$.ajax({
type: 'POST',
url: 'dashboard-table.php',
success: function(msg) {
$("#table-container").html(msg);
console.log("loaded");
}
});
}, 5000);
It basically scrolls down to the next .job-item
which is not completely on screen, using the jquery.visible plugin. The issue is that as the page is updated via ajax, the "seen" elements lose the seen class, meaning I would like to store which element was last visible and search over the rows from there.
That is unless anyone has any alternatives which would be greatly appreciated.
FIDDLE: http://jsfiddle.net/yn4wxsej/