Here is a suggested solution:
$(window).scroll(function () {
var distanceFromBottom = 100;
if ( ( $("#outerBox").offset().top + $("#contentBox").height() - $(window).scrollTop() ) > $(window).height() - distanceFromBottom ) {
$("#contentBox").fadeOut("slow");
} else {
$("#contentBox").fadeIn("slow");
}
})
The code above assumes that you want the content to fade back in when it is greater than 100 pixels from the bottom. If this is not the desired behavior, simply adjust the if statement accordingly.
It appears that you are implementing this effect on a music player. Keep in mind that fading or hiding an embedded object may not provide a smooth animation using jQuery. The script provided will still work, but the revised version below simplifies by using only one div and the embedded object within it. Ensure that the outer div closely wraps the inner div for proper functionality.
$(window).scroll(function () {
var distanceFromBottom = 100;
if ( ( $(".mediaPlayer").offset().top + $(".mediaPlayer object").height() - $(window).scrollTop() ) > $(window).height() - distanceFromBottom ) {
$(".mediaPlayer object").hide();
} else {
$(".mediaPlayer object").show();
}
})
I have made adjustments based on your requirements and shared the updated code on this pastebin link for reference.
Edit: Corrected the logic for disappearing when closer to the bottom by changing the "<" to ">". The pastebin code has also been updated accordingly.