JS Wordpress

How to add scripts after scroll

Add script after page scroll:

Copy and paste following code into your js file and add your script to addscriptfunc function


function loadJSFile(file) {
var jsElement = document.createElement("script");
jsElement.type = "application/javascript";
jsElement.src = file;
jsElement.async = true;
document.body.appendChild(jsElement);
}

var addscript = false;

function addscriptfunc()
{
if (addscriptfunc === true) return;

loadJSFile('https://kkduniya.com/wp-content/plugins/jetpack/modules/widgets/social-icons/social-icons-admin.js?ver=20170506');
loadJSFile('https://kkduniya.com/wp-content/plugins/elementor/js/jquery.min.js');
addscript = true;
}

function initScript()
{
if (addscript === true) return;

if($(window).scrollTop()>1000){
addscriptfunc();
}
}

document.addEventListener("scroll", function(){
initScript();
});

Advertisement

Did you find this helpful? Share it!

Leave a Comment

Your email address will not be published. Required fields are marked