0

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>

1 Answers1

0

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);
});
Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313