[英]How to make content disappear when you scroll passed it?
I am making a scroll effect in JavaScript.我正在 JavaScript 中制作滚动效果。 I can make it appear when you scroll down, but how to make it disappear when you scroll past it?
我可以让它在你向下滚动时出现,但是当你滚动过去时如何让它消失呢?
this is what I got so far.这就是我到目前为止所得到的。
window.onload = function(){
const EFFECT = document.querySelector("#about_page");
window.addEventListener('scroll', scrollEffect);
function scrollEffect(){
if(window.scrollY >= 550) {
EFFECT.style.opacity = '1';
EFFECT.style.transform = 'scale(1)';
EFFECT.style.transition = '500ms ease-in-out';
}
else if(window.scrollY <= 500) {
EFFECT.style.opacity = '0';
EFFECT.style.transform = 'scale(0)';
EFFECT.style.transition = '500ms ease-in-out';
}
else {
EFFECT.style.opacity = '0';
EFFECT.style.transform = 'scale(0)';
}
}
scrollEffect();
}
Add an upper-bound to your first if
statement:为您的第一个
if
语句添加一个上限:
if(window.scrollY >= 550 && window.scrollY < 750) {
Just replace 750
with whatever value you want to trigger the fade-out.只需将
750
替换为您想要触发淡出的任何值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.