$("html").animate({scrollTop:$(document).height()},"slow");如果在底部,请不要滚动 [英] $("html").animate({ scrollTop: $(document).height() }, "slow"); if it's at the bottom don't scroll it

查看:110
本文介绍了$("html").animate({scrollTop:$(document).height()},"slow");如果在底部,请不要滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have three buttons which have hidden divs, when i click on one i want the content to scroll to the bottom, then when i click another I want the page to stay where it is but load the new content.

我尝试了变量和if语句

I've tried variables and if statements

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
        }
});

有什么想法吗? 感谢您的回答!

Any ideas? Thanks for the answers!

对不起,我真的不认为我已经向自己解释过, http://ephemurl.com/4w/5ws 这是我最后一刻的情况弹跳6个部分以滚动到文档的底部,但是我希望这种情况只发生一次,然后在接下来的5次单击中不进行动画处理,因为您已经在其中了...

Sorry i don't really think i've explained myself, http://ephemurl.com/4w/5ws here, is what I have at the minute, the last 6 sections bounce to scroll to the bottom of the document, but i want this to only happen once and then for the next 5 clicks don't animate because you're already there...

推荐答案

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

just use $(body) instead of $(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
        }
});
});

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

You can also use unbind within the event trigger to make it run only once

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

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

            $(this).unbind("click");
});

这篇关于$("html").animate({scrollTop:$(document).height()},"slow");如果在底部,请不要滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆