簡體   English   中英

向上滾動時淡出ID

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM