使用 jQuery 页面回到顶部

function backTop() {
    $(window).scroll(function () {
        if ($(window).scrollTop() > 100) {
            $("#topImg").fadeIn(1000);
        }
        else {
            $("#topImg").fadeOut(1000);
        }
    });

    //当点击跳转链接后,回到页面顶部位置
    $("#topImg").click(function () {
    //考虑到兼容性使用 body 和 html $('body,html').animate({ scrollTop: 0 }, 800); return false; }); }

  CSS 样式和HTML中的跳转图片设置如下:

#topImg{
    position:fixed;
    right:15px;
    bottom:30px;
    display:none;
}



    <img id="topImg" src="../images/top.PNG" />

  

posted @ 2015-01-14 17:32  Young汨  阅读(260)  评论(0编辑  收藏  举报