Выполнить функцию при скролле js
Подскажите пожалуйста, как я могу выполнить функцию когда scroll документа равен позиции элемента #footer?
$(document).on('scroll', function() {
var s = $(this).scrollTop();
var scroll_footer = $('#footer').position().top;
$("#console").text(s + " " + scroll_footer);
if (s >= scroll_footer) {
console.log("load");
}
});
#block {
background: red;
width: 250px;
}
#child_block {
padding-top: 100px;
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.child {
width: 100px;
height: 100px;
background: blue;
margin: 15px 10px 10px;
15px;
display: flex;
align-items: center;
justify-content: center;
color: #fff;
}
#footer {
width: 100%;
height: 10px;
background: gray;
}
#console {
position: fixed;
left: 300px;
top: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="block">
<div id="child_block">
<div class="child">1</div>
<div class="child">2</div>
<div class="child">3</div>
<div class="child">4</div>
<div class="child">5</div>
<div class="child">6</div>
<div class="child">7</div>
<div class="child">8</div>
</div>
<div id="footer"></div>
</div>
<div id="console"></div>