0

I have a website and the footer has a JavaScript code.

I want my JavaScript code to run only if the user open scroll down to that part of the website.

VXp
  • 10,307
  • 6
  • 25
  • 40
Valona
  • 199
  • 2
  • 12

2 Answers2

0

You can run your code when footer is .visible(true).

something like this:

if ($('#footer').visible(true)) {
    // The element is visible, do something
} else {
    // The element is NOT visible, do something else
}
Nasim
  • 215
  • 2
  • 13
0

You may separate your js code in file and when user scroll down append that to your footer section like below.

$(window).scroll(function() {
       if($(window).scrollTop() + $(window).height() == $(document).height()) {
           var YourScript= document.createElement('script');
            YourScript.setAttribute('type', 'text/javascript');
            YourScript.src = 'js source path may be cdn ........';
            document.getElementById('Your-Footer-Div-ID').appendChild(YourScript);
       }
 });
Shree
  • 18,997
  • 28
  • 86
  • 133