Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Function is not only calling once

I am trying to execute only once, But it is executing multiple times.
I am showing alert when user reaches the 90% of the page while scrolling.
But it is showing alert multiple times.

I have also tried :-

  • By turning statement to true after executed.

But it didn’t worked.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

page.html

var percent = 90;
var window_scrolled;

$(window).scroll(function() {
    window_scrolled = ($(document).height()/100)*90;

    if($(window).scrollTop() + $(window).height() >= window_scrolled) {
        var excuted = false
        if (!excuted) {
            alert("scrolled to bottom");
            excuted = true

        }
    }
});

Any help would be much Appreciated. Thank You

>Solution :

You are always setting to false the excuted each time, so it always runs.

Try this:

var excuted = false
$(window).scroll(function() {
    window_scrolled = ($(document).height()/100)*90;
    if($(window).scrollTop() + $(window).height() >= window_scrolled) {
        if (!excuted) {
            alert("scrolled to bottom");
            excuted = true
        }
    }
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading