开发者

$("html").animate({ scrollTop: $(document).height() }, "slow"); if it's at the bottom don't scroll it

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.

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!

Edit: Sorry开发者_JAVA百科 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...


just use $(body) instead of $(html)

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

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


Don't Know what exactly you're trying to do, I guess this should help you,

$('#link-slide13').toggle(function(){
    $("html").animate({ scrollTop: $(document).height() }, "slow");
},function(){
    //don't do anything
})

Good Luck


We can't watch your html, but I think that you only have applied the function to one button witch id="link-slide13". If it must works in the three buttons change your JQuery selector. (adding a class to all buttons you can select all easy whith $(".className")).

Then, what is a button? a link an input? If the button is a link

<a href="#">

you can add a "return false" sentence at the end of the function. This prevent that the link works as default and the navegator go to the top of the document.

But, really...what's the problem?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜