onscroll add class when component touch on top jquery
<!DOCTYPE HTML>
<html>
<head>
<title>
JQuery
| Detecting when user scrolls to bottom of div.
</title>
</head>
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js">
</script>
<body style="text-align:center;"
id="body">
<h1 style="color:green;">
GeeksForGeeks
</h1>
<p id="GFG_UP"
style="font-size: 17px;
font-weight: bold;">
</p>
<div class="div">
<h1>GeeksforGeeks</h1>
<h1>GeeksforGeeks</h1>
<h1>GeeksforGeeks</h1>
<h1>GeeksforGeeks</h1>
<h1>GeeksforGeeks</h1>
<h1>GeeksforGeeks</h1>
<h1>GeeksforGeeks</h1>
<h1>GeeksforGeeks</h1>
<h1>GeeksforGeeks</h1>
<h1>GeeksforGeeks</h1>
<h1>GeeksforGeeks</h1>
<h1>GeeksforGeeks</h1>
<h1>GeeksforGeeks</h1>
</div>
<script>
$('#GFG_UP').text(
'Scroll till bottom to get alert!');
$(window).on('scroll', function() {
if ($(window).scrollTop() >= $(
'.div').offset().top + $('.div').
outerHeight() - window.innerHeight) {
alert('You reached the end of the DIV');
}
});
</script>
</body>
</html>