创建"滚动到顶部"按钮

BrB*_*rBa 2 html javascript css jquery scroll

我想在Lenta.ru中创建一个类似的按钮,具有平滑的可伸缩效果,你可以帮助我吗?

yey*_*ene 13

查看此演示http://jsfiddle.net/yeyene/J3zyq/3/

$(document).ready(function() {
    $(window).scroll(function() {
        if($(this).scrollTop() > 100){
            $('#goTop').stop().animate({
                top: '20px'    
                }, 500);
        }
        else{
            $('#goTop').stop().animate({
               top: '-100px'    
            }, 500);
        }
    });
    $('#goTop').click(function() {
        $('html, body').stop().animate({
           scrollTop: 0
        }, 500, function() {
           $('#goTop').stop().animate({
               top: '-100px'    
           }, 500);
        });
    });
});   
Run Code Online (Sandbox Code Playgroud)