I had been thinking about the problem of attaching a scroll event (pointed out by @AndrewWhitaker), and my final thoughts are that there is no need to add a scoll event handler every x seconds, since you can just execute a setInterval and check in the callback whether the alert should be shown or not. e.g:
var showMessageInterval = window.setInterval(showMessageIfNeeded, 500);
// you could adjust the interval to the animation duration of the
// message showing. In this way, the delay will be more "natural"
The showMessageIfNeeded
callback would check the scrollTop
value and show the message if needed. If the message is displayed, the setInterval
have to be cleared to avoid the next executions:
function showMessageIfNeeded() {
var scrollTop = $(window).scrollTop();
var targetTop = $(".myPara").offset().top;
if (scrollTop > targetTop) {
alert('Show message');
window.clearInterval(showMessageInterval);
}
}