Javascript 如何在滚动到底部时隐藏div,在向上滚动到顶部时再次显示div?

Javascript 如何在滚动到底部时隐藏div,在向上滚动到顶部时再次显示div?,javascript,jquery,Javascript,Jquery,当你们来到页面底部时,我想把卷轴藏起来。 我编写了这段代码,它运行良好: <script> document.onscroll = function() { if (window.innerHeight + window.scrollY > document.body.clientHeight) { document.getElementById("scroller").style.display='hide'; }

当你们来到页面底部时,我想把卷轴藏起来。 我编写了这段代码,它运行良好:

<script>
document.onscroll = function() {
        if (window.innerHeight + window.scrollY > document.body.clientHeight) {
            document.getElementById("scroller").style.display='hide';
        }


    }
</script>

document.onscroll=函数(){
if(window.innerHeight+window.scrollY>document.body.clientHeight){
document.getElementById(“scroller”).style.display='hide';
}
}
但是现在当你回到顶部时,卷轴也被隐藏了


当用户滚动回顶部时,我想再次显示“scroller”。

只需添加一个显示它的else案例:

if (window.innerHeight + window.scrollY > document.body.clientHeight) {
     document.getElementById("scroller").style.display='none';
}
else{
     document.getElementById("scroller").style.display='block';
}

只需添加显示它的else案例:

if (window.innerHeight + window.scrollY > document.body.clientHeight) {
     document.getElementById("scroller").style.display='none';
}
else{
     document.getElementById("scroller").style.display='block';
}

document.onscroll=函数(){
if(window.innerHeight+window.scrollY>document.body.clientHeight){
document.getElementById(“scroller”).style.display='hide';
}否则{
document.getElementById(“scroller”).style.display='block';
}
}

document.onscroll=函数(){
if(window.innerHeight+window.scrollY>document.body.clientHeight){
document.getElementById(“scroller”).style.display='hide';
}否则{
document.getElementById(“scroller”).style.display='block';
}
}
}))

在JQuery中,您可以使用这个

}))


在JQuery中,您可以使用它。

尝试以下操作

$(window).scroll(function() {
   if($(window).scrollTop() + $(window).height() == $(document).height()) {
       $('#scroller').hide('slow');
   } 
   else if($(window).scrollTop()==0)
   {
          $('#scroller').show('slow');
   }
});

尝试以下操作

$(window).scroll(function() {
   if($(window).scrollTop() + $(window).height() == $(document).height()) {
       $('#scroller').hide('slow');
   } 
   else if($(window).scrollTop()==0)
   {
          $('#scroller').show('slow');
   }
});

$(“#scroller”).toggle(window.innerHeight+window.scrollY或
document.getElementById(“scroller”).style.display=window.innerHeight+window.scrollY>document.body.clientHeight?'none':'block'
别忘了取消事件处理程序的盎司!
$(“#scroller”).toggle(window.innerHeight+window.scrollY或
document.getElementById(“滚动条”).style.display=window.innerHeight+window.scrollY>document.body.clientHeight?'none':'block'
别忘了对eventhandler进行去盎司处理!三元组会更好elegant@mplungjan但是,也许代码正在执行一些问题中没有显示的其他过程,这很可能是不可能的elegant@mplungjan但也许是公司de正在做一些问题中没有显示的其他过程,非常不可能三元会更优雅-没有,没有hideA三元会更优雅-没有,没有隐藏