[英]Fade out ID when scroll up
该代码在向下滚动时效果很好,但是我试图使向上滚动时的id也逐渐消失。
<script>
tiles = $("#widgeted-title1").fadeTo(0, 0);
$(window).scroll(function(d,h) {
tiles.each(function(i) {
a = $(this).offset().top + $(this).height();
b = $(window).scrollTop() + $(window).height();
if (a < b) $(this).fadeTo(500,1);
});
});
</script>
如果您的代码有效(用于淡入),那么您所需要做的就是:
var tiles = $("#widgeted-title1").fadeTo(0, 0);
$(window).on("scroll resize", function() { // do it also on resize!
var a = tiles.offset().top + tiles.height();
var b = $(this).scrollTop() + $(this).height();
tiles.stop().fadeTo(500, a<b ? 1 : 0);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.