使用jQuery获取scrollbottom(Getting the scrollbottom using jQuery)

编程入门 行业动态 更新时间:2024-10-28 08:29:48
使用jQuery获取scrollbottom(Getting the scrollbottom using jQuery)

我有以下代码,它获取用户从顶部和底部滚动的数量,然后使用这些值,它应隐藏或显示阴影。

$(document).ready(function() { if ( $(window).scrollTop() + $(window).height() >= $(window).height() ) { $('div.shadow-bottom').show(); } $(window).scroll(function () { if ( $(window).scrollTop() >= 15 ) { $('div.shadow-top').show(); } else { $('div.shadow-top').hide(); } if ( $(window).scrollTop() + $(window).height() >= $(window).height() - 15 ) { $('div.shadow-bottom').show(); } else { $('div.shadow-bottom').hide(); } }); });

顶部工作正常,但当你到达页面底部时底部应该隐藏但是如果你是从底部15像素再次显示。

示例: http : //dev.driz.co.uk/shadow/

I have the following code which gets the amount the user has scrolled from the top and the bottom and then using these values it should hide or show the shadows.

$(document).ready(function() { if ( $(window).scrollTop() + $(window).height() >= $(window).height() ) { $('div.shadow-bottom').show(); } $(window).scroll(function () { if ( $(window).scrollTop() >= 15 ) { $('div.shadow-top').show(); } else { $('div.shadow-top').hide(); } if ( $(window).scrollTop() + $(window).height() >= $(window).height() - 15 ) { $('div.shadow-bottom').show(); } else { $('div.shadow-bottom').hide(); } }); });

The top works fine, but the bottom one should be hiding when you get to the bottom of the page BUT then show again if you are 15 pixels from the bottom.

Example: http://dev.driz.co.uk/shadow/

最满意答案

$(窗口).height(); //返回浏览器视口的高度

的$(document).height(); //返回HTML文档的高度

将您的代码更改为:

$(document).ready(function() { if ($(window).scrollTop() + $(window).height() >= $(document).height() - 15) { $('div.shadow-bottom').show(); } $(window).scroll(function() { if ($(window).scrollTop() >= 15) { $('div.shadow-top').show(); } else { $('div.shadow-top').hide(); } if ($(window).scrollTop() + $(window).height() >= $(document).height() - 15) { $('div.shadow-bottom').show(); } else { $('div.shadow-bottom').hide(); } }); });​

$(window).height(); // returns height of browser viewport

$(document).height(); // returns height of HTML document

Change your code to:

$(document).ready(function() { if ($(window).scrollTop() + $(window).height() >= $(document).height() - 15) { $('div.shadow-bottom').show(); } $(window).scroll(function() { if ($(window).scrollTop() >= 15) { $('div.shadow-top').show(); } else { $('div.shadow-top').hide(); } if ($(window).scrollTop() + $(window).height() >= $(document).height() - 15) { $('div.shadow-bottom').show(); } else { $('div.shadow-bottom').hide(); } }); });​

更多推荐

本文发布于:2023-08-06 12:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1448500.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:jQuery   scrollbottom

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!