简体   繁体   English

刷新页面滚动到页面顶部

[英]Refresh page on scroll to top of page

I am creating a website in php , in which I want a division to reload by javascript when the user scroll to the top of the page. 我正在用php创建一个网站,当用户滚动到页面顶部时,我希望该部门可以通过javascript reload

Can anyone guide me how to do this with example? 谁能指导我使用示例来做到这一点?

With using something like jQuery you can do it like this; 通过使用类似jQuery的工具,您可以做到这一点;

$(window).scroll(function () { 

   var offset = 50;

   if( $(window).scrollTop() <= offset ) {

   // Reload your division    
   //

   }

 });

Note; 注意; the .scroll function is firing each pixel you scroll, for browserload you might want to add a timeout for this .scroll函数会触发您滚动的每个像素,对于浏览器加载,您可能需要为此添加超时

You need to watch the scrollTop value. 您需要观看scrollTop值。 Simple example: 简单的例子:

$(window).scroll(function () { 
    if ( $(window).scrollTop <= 30 ) {
        window.location.reload();
    }
});

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

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