如何在JQuery中调用动画后重新加载

时间:2015-06-13 14:56:13

标签: javascript jquery

我正在构建一个新闻Feed页面,它会自动滚动到底部,然后等待并刷新页面并重复此过程。

此刻自动重装不起作用,它开始让我烦恼。

非常感谢任何帮助。

滚动部分效果很好

我的代码目前

<script language="javascript" type="text/javascript">
function scrolll() {
    time = $('.message').length*3000;
    $("html, body").animate({ scrollTop: 0 }, 0);
        $("html, body").animate({ scrollTop: $(document).height() }, time,0, function() {location.reload; });
        ;
    }
</script>

2 个答案:

答案 0 :(得分:0)

你可以使用

location.reload();

window.location.href = window.location.href;

但我认为你的问题是时间,0

$("html, body").animate({ scrollTop: $(document).height() }, time, function() {location.reload(); });

如果我明白你可以使用setTimeout()

$("html, body").animate({ scrollTop: $(document).height() }, 100, function() { 
        setTimeout(function() {
            location.reload();
        }, time)
});

DEMO

答案 1 :(得分:0)

首先,尝试更改

location.reload; 

location.reload(true);

(这也将避免在重新加载时使用页面缓存(ref))。

接下来,考虑动画签名:

  

.animate(properties [,duration] [,easing] [,complete])

在动画中,您将0作为缓动名称

.animate({...}, time, 0, function() ...

将阻止动画启动。要么完全省略,要么传入有效的缓动名称,例如“linear”。如果您有兴趣,请参阅here以了解功能名称。