[英]How to show a div when the user scrolls to the end of the page?
http://codepen.io/BrianDGLS/pen/yNBrgR http://codepen.io/BrianDGLS/pen/yNBrgR
This is what I am currently using which allows the user to track where he is on the page. 这就是我目前正在使用的内容,它允许用户跟踪他在页面上的位置。
What would I have to do to show a div when the user reaches the bottom of the page? 当用户到达页面底部时,我需要做什么才能显示div? And continue to show it until he hits refresh 并继续显示它直到他点击刷新
#show {display: none} #show {display:none}
<div id="show">
<p>Hello</p>
<p>World!</p>
</div>
Show the div '#show' when the user reaches the bottom of the page and continue to show it for as long as he stays on the page. 当用户到达页面底部时显示div'#show',并在他停留在页面上时继续显示它。
Using a convention that mirrors the sample JS code: 使用镜像示例JS代码的约定:
$(window).scroll(function() {
var wintop = $(window).scrollTop(),
docheight = $(document).height(),
winheight = $(window).height(),
scrolled = (wintop / (docheight - winheight)) * 100;
if (scrolled >= 100) {
$(yourDiv).show();
}
});
The computation of the scroll percentage is straight from the link you provided and the condition just checks if you've reached 100% of the page (minus current window size). 滚动百分比的计算是直接来自您提供的链接 ,条件只是检查您是否已达到页面的100%(减去当前窗口大小)。
You could also change 100 to be whatever percentage if you want to load the div before the user reaches the absolute bottom. 如果要在用户到达绝对底部之前加载div,也可以将100更改为任何百分比。
It could be something like: 它可能是这样的:
$(window).on('scroll', function(){
var op = $(window).scrollTop() + $(window).height();
if( op >= $(document).height() ) $("#show").show();
});
当<div id="show">
在客户端的视口中可见时,您需要触发Javascript函数,因为您可以使用插件
try below code 尝试以下代码
var show=false;
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height() || show==false) {
$("#show").show();
show=true;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.