【发布时间】:2019-03-05 18:36:24
【问题描述】:
让我解释一下我要做什么。我有一个控制滚动链接动画的功能。我想在requestAnimationFrame() 中调用它,但我想将window.pageYOffset 作为函数的参数传递。现在代码如下所示:
let wH = window.offsetHeight;
let ticking = false
function effects(wT, wH){
//animations using wT, wH
};
window.onresize = () => {
if (!ticking) {
wH = window.offsetHeight;
const wT = window.pageYOffset;
//I want to pass the wT, and wH to the rAF's parameter,
//which is the function above. How?
requestAnimationFrame(effects);
ticking = true;
}
}
window.onscroll = () => {
const wT = window.pageYOffset;
if (!ticking) {
//I want to pass the wT, and wH to the rAF's parameter,
//which is the function above. How?
requestAnimationFrame(effects);
ticking = true;
}
}
【问题讨论】:
标签: javascript