向上滚动时淡出ID

时间:2015-03-16 02:58:44

标签: javascript jquery scroll

此代码适用于向下滚动,但即时尝试也可以在向上滚动时淡出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>

1 个答案:

答案 0 :(得分:0)

如果您的代码(淡入淡出)适用于所有您需要的代码:

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);
});
相关问题