我希望通过应用此功能从页面顶部下拉一些单词
function dropWord(){
var word = document.createElement("div");
body.insertBefore(word, document.getElementsByTagName("script")[0]);
word.classList.add("word");
var random = (Math.random() * (99 - 0)).toFixed(1);
word.style.left = `${random}%`
}
并在此处每 3 秒重复一次此函数
setInterval(dropWord(), 3000);
该函数工作一次后就无法继续,我确信我正在犯一些愚蠢的错误,任何帮助将不胜感激
最佳答案
setInterval
需要一个函数引用。您实际上正在调用该函数。你需要这个:
setInterval(dropWord, 3000); // notice the lack of () in the function
关于javascript - setinterval问题重复功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38505121/