简体   繁体   English

使用jquery每滚动三个底部,“查看更多”按钮

[英]“View More” button after every three bottom scroll using jquery

I have tried a lot but can't add show more button automatically just after every three scroll down. 我已经尝试了很多,但是每向下滚动三下就无法自动添加显示更多按钮。

When I am going to bottom of my page it scrolls down infinite times. 当我进入页面底部时,它会无限向下滚动。 I have to stop it after three scrolls and want to add "view more" button after every three scrolls. 我必须在三滚动之后停止它,并想在每三滚动之后添加“查看更多”按钮。

try something like this: 尝试这样的事情:

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <!DOCTYPE html> <html> <head> <style> body { width: 200px; height: 100px; overflow: scroll; } </style> </head> <body > <p>Try the scrollbar in div.</p> In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since. <br><br> 'Whenever you feel like criticizing anyone,' he told me, just remember that all the people in this world haven't had the advantages that you've had.' <p>Try the scrollbar in div.</p> In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since. <br><br> 'Whenever you feel like criticizing anyone,' he told me, just remember that all the people in this world haven't had the advantages that you've had.' <p>Try the scrollbar in div.</p> In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since. <br><br> 'Whenever you feel like criticizing anyone,' he told me, just remember that all the people in this world haven't had the advantages that you've had.' <p>Try the scrollbar in div.</p> In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since. <br><br> 'Whenever you feel like criticizing anyone,' he told me, just remember that all the people in this world haven't had the advantages that you've had.' <p>Scrolled <span id="demo">0</span> times.</p> <script> var lastScrollTop = 0; var x = 0; $(window).scroll(function(event){ var st = $(this).scrollTop(); if (st > lastScrollTop){ document.getElementById("demo").innerHTML = x += 1; if( x%3 == 0){ var i=document.createElement('button'); i.innerHTML="more"; document.getElementsByTagName('body')[0].appendChild(i); } } lastScrollTop = st; }); </script> </body> </html> 

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM