I have been experimenting with javascript and jquery to determine when the window scroll reaches the top of a specific element. Although I have been trying different methods, I have yet to see any successful outcomes:
fiddle: https://jsfiddle.net/jzhang172/opvb2csy/
$(window).scroll(function() {
var targetScroll = $('.div').position().top;
if($(window).scrollTop() > targetScroll){
alert('hey');
});
});
body,html{
height:2000px;
}
.div{
height:300px;
width:300px;
position:absolute;
top:500px;
background:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<div class="div"></div>