DEV Community

mhsohag11
mhsohag11

Posted on

Answer: Call function on scroll only once

Try using .one():

$(window).one('scroll',function() {
   // Stuff
});

Or, unlink the event inside:

$(window).on('scroll',function() {
   // After Stuff
   $(window).off('scroll');
});

Guess you might need this code:

$(window).on('scroll',function() {
    if (checkVisible($('#tester'))) {
        alert("Visible!!!");
        $(window).off('scroll');
    } else {
        // do nothing
    }
});

Fiddle: http://jsfiddle.net/c68nz3q6/

Top comments (0)