在页面底部使元素消失

时间:2016-02-11 02:19:20

标签: javascript jquery html css

我正在建立一个网站,但我不太了解javascript或jquery。我的主页上有一个向下箭头,显示有更多信息,但我希望它在用户滚动到页面底部时消失,因为它不再需要,因为它们不能向下滚动。我知道我需要javascript或jquery这样做,但我甚至不知道从哪里开始。救命啊!

2 个答案:

答案 0 :(得分:0)

尝试这样的事情:

document.onscroll = function() {
        if (window.innerHeight + window.scrollY > document.body.clientHeight) {
            document.getElementById('arrow').style.display='none';
        }
    }

其中'箭头'是图像的ID。

答案 1 :(得分:0)

使用jquery:

$(window).scroll(function(){
  var numPix = 200; // number of pixels before bottom of page that you want to start fading
  var op = (($(document).height() - $(window).height()) - $(window).scrollTop()) / numPix;
    if( op <= 0 ){
        $("#thing-to-hide").hide();
    } else {
        $("#thing-to-hide").show();
    }
    $("#thing-to-hide").css("opacity", op ); 
});
相关问题