[英]setinterval problems repeating function
我希望通过应用此功能从页面顶部下拉一些单词
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.