You really should use Intersection Observer (IO) for this. This was developed to solve problems as yours, to handle elements scrolling into view (and also out of view)
First you set the options for your observer. For example, you can specify how much the element has to be visible when the callback function should fire:
var options = {
rootMargin: '0px',
threshold: 1.0
}
var observer = new IntersectionObserver(callback, options);
Here we say the element has to be 100% visible (threshold: 1.0) -> Then the callback is executed.
Then we define which elements to watch:
var target = document.querySelectorAll('.media-tbl > tbody > tr');
observer.observe(target);
and last we define what should happen when the defined element scrolls into view:
var callback = function(entries, observer) {
entries.forEach(entry => {
// Each entry describes an intersection change for one observed
// target element:
});
};
If you need to support older browsers, use the official polyfill from w3c.