简体   繁体   English

Java向上滚动淡入,在滚动时停留,向上滚动淡入

[英]Java Scroll up Fade In, Stay While scrolling, Scroll Up Fade Out

I would like different elements to fade in as they reach the center of the screen (bottom to middle of screen) when scrolling, stay put while continuing to scroll, and then fade out as they scroll off the top of the screen. 我希望滚动时,不同的元素在到达屏幕中央(从底部到屏幕中间)时逐渐淡入,在继续滚动时保持原状,然后在滚动离开屏幕顶部时逐渐消失。

I can stop the element from scrolling at a certain put and use a fade in/out effect. 我可以停止元素在特定位置滚动,并使用淡入/淡出效果。

The issues I am having are getting the element to continue scrolling again after stopping, as well as controlling the beginning and end points of the opacity change. 我遇到的问题是使元素停止后继续继续滚动,以及控制不透明度更改的起点和终点。

$(window).scroll(function(){
    $("#theFixed").css("top",Math.max(150,450-$(this).scrollTop()));
});

$(document).ready(function(){
    $(window).scroll(function(){
        $("#theFixed").css("opacity", 0 + $(window).scrollTop() / 1200);
    });
});

<div id="theFixed" style="position:fixed;top:450px;background-color:red" >SOMETHING</div>

STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>STUFF <BR>

使用ScrollMagic, 对此示例进行检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM