$("html").animate({scrollTop:$(document).height()},"slow"); 如果它在底部不滚动它

Tar*_*ine 1 jquery scrollto

我有三个隐藏div的按钮,当我点击一个我希望内容滚动到底部,然后当我点击另一个我希望页面保持原样但加载新内容.

我尝试过变量和if语句

var i=0;
$('#link-slide13').click(function(){
        if (i==0){//nothing's been scrolled
            $("html").animate({ scrollTop: $(document).height() }, "slow");
            i=1;

        }else{
            //don't do anything
        }
});
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?谢谢你的回答!

编辑:对不起,我真的不认为我已经解释过自己, http://ephemurl.com/4w/5ws在这里,是我现在所拥有的,最后6个部分反弹滚动到文档的底部,但我希望这只发生一次然后接下来的5次点击不会动画,因为你已经在那里...

Qui*_*ncy 7

只需使用$(body)代替$(html)

演示 http://jsfiddle.net/APebY/

$(function(){
var i=0;
$('#link-slide13').click(function(){
        if (i==0){//nothing's been scrolled
            $("body").animate({ scrollTop: $(document).height() }, "slow");
            i=1;

        }else{
            //don't do anything
        }
});
});
Run Code Online (Sandbox Code Playgroud)

您还可以在事件触发器中使用unbind使其仅运行一次

$('#link-slide13').click(function(){

            $("body").animate({ scrollTop: $(document).height() }, "slow");

            $(this).unbind("click");
});
Run Code Online (Sandbox Code Playgroud)