我想创建两个变量函数,然后在三秒后激活它们。
$(window).scroll(function() {
let scroll = $(window).scrollTop();
let year2 = () => {
setTimeout(function() {
document.getElementById("year").innerHTML = "2+ years"
}, 3000);
}
let year3 = () => {
setTimeout(function() {
document.getElementById("year").innerHTML = "3+ years"
}, 6000);
}
let scrollOne = scroll > 20;
if (scrollOne) {
year2();
} else {
year3();
}
});
答案 0 :(得分:0)
您需要调用方法而不是返回它们:
if (scrollOne) {
year2();
}
else {
year3();
}
我删除了(year2 = true)
year2是一种方法,它不会成立,但它将始终被定义