[英]“View More” button after every three bottom scroll using jquery
我已經嘗試了很多,但是每向下滾動三下就無法自動添加顯示更多按鈕。
當我進入頁面底部時,它會無限向下滾動。 我必須在三滾動之后停止它,並想在每三滾動之后添加“查看更多”按鈕。
嘗試這樣的事情:
<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.