简体   繁体   中英

Fade out ID when scroll up

this code works well with scrolling down but im trying to make works as well to fade out the id when scroll up.

<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>

If your code works (for the fade-in) than all you need is:

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);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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