Here is a JSFiddle Demo
You need to select the element that you want as the target.
var someElement = document.querySelector('whatever');
Then you need set an scroll
event listener on the window
object itself, which fires every time the user scrolls, then simply run a if
statment to check if the element from the top of the screen is greater or equal to 0, if true
run the following block of code.
window.onscroll = function(){
//TOP
if(someElement.getBoundingClientRect().top <= 0){
console.log("TRIGGER: top of div reached.");
}
//BOTTOM
if(someElement.getBoundingClientRect().bottom <= 0){
console.log("TRIGGER: bottom of div reached.");
}
}