How to call a function multiple times?

Want to have the function triggered each time the scroll reaches the element is active. Only works with the first element, what to do?

April 3rd 20 at 17:22
1 answer
April 3rd 20 at 17:24
Solution
scrollTracking function() {
 const wt = $(window).scrollTop();
 const wh = $(window).height();

 $('#console').html($('.active').get().find(n => {
 const et = $(n).offset().top;
 const eh = $(n).outerHeight();
 return wt > et && wt + wh - eh * 2 <= et + (wh - eh);
 }) ? 'Running' : 'Not running');
}
@patsy_Gre , please tell me, as the element #console to change class at the same time? - Clarabelle.Mertz11 commented on April 3rd 20 at 17:27
@Clarabelle.Mertz11,

scrollTracking function() {
 const wt = $(window).scrollTop();
 const wh = $(window).height();

 const el = $('.active').get().find(n => {
 const et = $(n).offset().top;
 const eh = $(n).outerHeight();
 return wt > et && wt + wh - eh * 2 <= et + (wh - eh);
});

$('#console')
 .toggleClass('fucking class', !!el)
 .html(el ? 'Running' : 'Not running');
}
- patsy_Gre commented on April 3rd 20 at 17:30

Find more questions by tags jQuery