Javascript 使元素在页面底部消失
我正在制作一个网站,但我对javascript或jquery知之甚少。我的主页上有一个向下箭头,显示有更多的信息,但我希望当用户滚动到页面底部时,这些信息消失,因为这样就不需要了,因为他们不能再向下滚动了。我知道我需要javascript或jquery来完成这项工作,但我甚至不知道从哪里开始。救命啊 试试这样的方法:Javascript 使元素在页面底部消失,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我正在制作一个网站,但我对javascript或jquery知之甚少。我的主页上有一个向下箭头,显示有更多的信息,但我希望当用户滚动到页面底部时,这些信息消失,因为这样就不需要了,因为他们不能再向下滚动了。我知道我需要javascript或jquery来完成这项工作,但我甚至不知道从哪里开始。救命啊 试试这样的方法: document.onscroll = function() { if (window.innerHeight + window.scrollY > docu
document.onscroll = function() {
if (window.innerHeight + window.scrollY > document.body.clientHeight) {
document.getElementById('arrow').style.display='none';
}
}
其中“arrow”是图像的id。尝试以下方法:
document.onscroll = function() {
if (window.innerHeight + window.scrollY > document.body.clientHeight) {
document.getElementById('arrow').style.display='none';
}
}
其中“arrow”是图像的id。使用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 );
});
$(窗口)。滚动(函数(){
var numPix=200;//要开始淡入的页面底部之前的像素数
var op=($(document.height()-$(window.height())-$(window.scrollTop())/numPix;
如果(op使用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 );
});
$(窗口)。滚动(函数(){
var numPix=200;//要开始淡入的页面底部之前的像素数
var op=($(document.height()-$(window.height())-$(window.scrollTop())/numPix;
如果(op抱歉我的无知,但我只是把它放在html文件的脚本标记中吗?是的,你可以这样做。因为我的答案不依赖于jquery,你不必担心引用它或其他任何东西。如果你仍然有问题,请告诉我。抱歉我的无知,但我只是把它放在html文件的脚本标记中吗?是的,你可以这样做。因为我的答案不依赖于jquery,所以您不必担心引用它或其他任何东西。如果您仍然有问题,请告诉我。