0

How to load script only after scroll

I want to load script only after user scroll down to certain position. I tried this jquery method but it is not working. Any idea?  $( window ).scrollTop(800);   $.ajax({   url: 'https://externalscript.comt/my.js',   dataType: 'script',   cache: true,    });  });

25th Feb 2020, 10:09 AM
Uzair Malim
Uzair Malim - avatar
3 Réponses
+ 2
replace alert with the script you want
25th Feb 2020, 10:16 AM
Gordon
Gordon - avatar
+ 1
let flag = false; document.onscroll = () => { if (scrollY > 300 && flag == false) {flag = true; alert("reached")}} https://code.sololearn.com/We0x0YDN9C9N/?ref=app
25th Feb 2020, 10:12 AM
Gordon
Gordon - avatar
0
Gordon but how to call javascript
25th Feb 2020, 10:16 AM
Uzair Malim
Uzair Malim - avatar