I have a question regarding a function that will be called if the object is on my screen. But when the object is on my screen, the function is called and a warning is called. But if I close the warning and scroll further, the event will be raised again. I do not need this. How can i solve this?
Working example
My code is:
<div id="wrapper"> scroll down to see the div </div> <div id="tester"></div>
Js
$(window).on('scroll',function() { if (checkVisible($('#tester'))) { alert("Visible!!!") } else { // do nothing } }); function checkVisible( elm, eval ) { eval = eval || "object visible"; var viewportHeight = $(window).height(), // Viewport Height scrolltop = $(window).scrollTop(), // Scroll Top y = $(elm).offset().top, elementHeight = $(elm).height(); if (eval == "object visible") return ((y < (viewportHeight + scrolltop)) && (y > (scrolltop - elementHeight))); if (eval == "above") return ((y < (viewportHeight + scrolltop))); }
I want the If function to be called only 1 time, and not on every scroll if the object is visible.
source share