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
  • 11,598
  • 6
  • 31
  • 46
Nzui Manto
  • 349
  • 5
  • 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
  • 325
  • 2
  • 14
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);
       }
 });
4b0
  • 21,981
  • 30
  • 95
  • 142