I've set up a jsfiddle that seems to do what you want http://jsfiddle.net/LYw8m/.
Here is the javascript using jQuery's .offset()
and .scroll()
functions:
Edit: I just realised you probably only want to fire this when the div first appears. http://jsfiddle.net/LYw8m/2/
Edit again:
I've added the if statement to outside the .scroll()
to solve the issue in your comment if the div is already visible.
Updated js:
$(document).ready(function(){
var event_fired = false;
if( $("#alert").offset().top <= ( $(this).offset().top + $(this).height() )
&& !event_fired ){
alert('Ok!');
event_fired = true;
}
$(".overflow").scroll(function(){
if( $("#alert").offset().top <= ( $(this).offset().top + $(this).height() )
&& !event_fired ){
alert('Ok!');
event_fired = true;
}
else if ( $("#alert").offset().top > ( $(this).offset().top + $(this).height() ){
event_fired = false;
}
});
});