【问题标题】:Refresh the content when it reaches to its end "div"当内容到达结尾“div”时刷新内容
【发布时间】:2016-09-15 09:22:19
【问题描述】:

我希望我的页面在自动向下滚动后自动刷新...这是我关于如何自动上下滚动的代码。

function scroll(speed) {
$('html, body').animate({ scrollTop: $(document).height() }, speed, function() {
    $(this).animate({ scrollTop: 0 }, speed);
});
}

speed = 25000;

scroll(speed)
setInterval(function(){scroll(speed)}, speed * 2);

【问题讨论】:

  • 多解释一点
  • 如果它在触底时刷新,那么您不会看到它返回?你可以在你的第二个动画中添加另一个完整的函数,比如function(){ location.reload(); },这样你就不需要你的 setInterval 调用了。
  • 所以你的意思是@Sam0,我将替换 setInterval(function(){scroll(speed)}, speed * 2); to function(){ location.reload(); } ??

标签: jquery ajax jquery-animate


【解决方案1】:

这里有个小技巧:https://jsfiddle.net/manoeuvres/LbLaf8La/ 在第二个动画调用的“动作完成”函数中添加了刷新调用 location.reload();,所以当动画返回顶部时它会刷新。

function scroll(speed) {
$('html, body').animate({ scrollTop: $(document).height() }, speed, function() {
    $(this).animate({ scrollTop: 0 }, speed, function(){ location.reload(); });
});
}

speed = 25000;

scroll(speed)
setInterval(function(){scroll(speed)}, speed * 2); // because the page is refreshing I don't think this line gets to get called. but no problem to leave it in.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-07
    • 1970-01-01
    相关资源
    最近更新 更多