简体   繁体   English

当用户滚动到页面末尾时如何显示div?

[英]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;
   }
});

如何知道用户何时滚动过去<div> ?</div><div id="text_translate"><p> 我正在构建一些东西,向用户展示他们没有看到的项目。</p><p> 每个项目都在一个&lt;div&gt;中,因此当用户滚动过去一个 div 或查看该 div 时,我希望将该项目标记为已被看到。</p><p> 谷歌阅读器会这样做,如果您滚动浏览提要中的某个项目,它会自动将其标记为已读。</p><p> 如何跟踪? 请指教。</p><p> 注意:不应仅限于使用鼠标滚动、向下/向上翻页、使用箭头键等也应计算在内。 主要标准是用户已经看到了一个 div。</p></div> - How to know when a user scrolls past a <div>?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当用户向下滚动页面时显示隐藏的div - Show a hidden div when the user scrolls down the page 当用户滚动到页面顶部时,如何才能使此代码仅显示div标签? - How can I go about making this code only show the div tag when the user scrolls to the top of the page? 如何仅在用户在div上滚动时显示滚动条 - How to show scrollbar only when user scrolls on a div 当用户滚动到页面末尾时自动点击 - Auto click when user scrolls to the end of the page 用户向下滚动页面时淡入div? - fade in div when user scrolls down page? 当用户滚动到页面底部时显示页脚 - Show footer when user scrolls to the bottom of the page 如何知道用户何时滚动过去<div> ?</div><div id="text_translate"><p> 我正在构建一些东西,向用户展示他们没有看到的项目。</p><p> 每个项目都在一个&lt;div&gt;中,因此当用户滚动过去一个 div 或查看该 div 时,我希望将该项目标记为已被看到。</p><p> 谷歌阅读器会这样做,如果您滚动浏览提要中的某个项目,它会自动将其标记为已读。</p><p> 如何跟踪? 请指教。</p><p> 注意:不应仅限于使用鼠标滚动、向下/向上翻页、使用箭头键等也应计算在内。 主要标准是用户已经看到了一个 div。</p></div> - How to know when a user scrolls past a <div>? 当用户滚动到页面末尾时,使用jQuery .load() - using jQuery .load() when user scrolls to the end of page 固定到页面顶部的部分标题div当用户滚动到部分时 - Fixed header div of section at top of page when user scrolls to section 当用户滚动时,我希望div在页面底部滚动 - I want a div to scroll at the bottom of the page when the user scrolls
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM