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.
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.
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
}
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);
}
});