JQuery置顶

来源:互联网 发布:中国软件管理学校 编辑:程序博客网 时间:2024/04/27 22:54
<script type="text/javascript">
    $(function(){
        //置顶按钮显示/隐藏实现
        $(window).scroll(function(){
            var w_height = $(window).height();//浏览器高度
            var scroll_top = $(document).scrollTop();//滚动条到顶部的垂直高度
            if(scroll_top > w_height){
                    $("#goto-top").fadeIn(500);
                }else{
                    $("#goto-top").fadeOut(500);
            }
        });
    //置顶
    $("#goto-top").click(function(e){
            e.preventDefault();
            $(document.documentElement).animate({
                scrollTop: 0
                },200);
            //支持chrome
            $(document.body).animate({
                scrollTop: 0
                },200);
        });
    })

</script>

<a href="#" title="返回顶部" id="goto-top">---</a>

0 0