var element = document.querySelector("#menu");
document.onscroll = function() {
if (document.body.scrollTop > 200 && document.body.scrollTop < (document.body.scrollHeight - 500))
{
element.style.display = "block";
}
else
{
element.style.display = "none";
}
};