如何停止scrollTop的持续时间

里斯·格芬

我现在使用的指令到目前为止已经足够好了,但是并不是每个页面都具有相同的高度,因此我想在持续时间已经到达底部时停止持续时间。

这是指令的代码:

function (scope, elem, attrs) {
        $(document).on('contentchanged', '#mainText',  function () {
            $("html, body").animate({
                scrollTop: 0
            }, 0),
            $("html, body").animate({
                scrollTop: $(window).height()
            }, 4000);
        });
    }

因此,例如,在第一页中,视图位于底部,它不能再降低;当我进入下一个较低的页面时,它会持续向下滚动。

我的问题是如何停止滚动?

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

因此您可以执行以下操作:

.animate( 
    {scrollTop:'300px'},
    300,
    swing,
    function(){ 
       alert(animation complete! - your custom code here!); 
       } 
    )

这是jQuery .animate函数api页面:http ://api.jquery.com/animate/

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章