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 Answers
+ 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