码迷,mamicode.com
首页 > Web开发 > 详细

返回顶部js

时间:2014-10-25 11:51:22      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:返回顶部   style   blog   http   color   io   os   ar   sp   

bubuko.com,布布扣

backToTop.js:

(function () {
    var $backToTopEle = $(‘<div class="backToTop"></div>‘).appendTo($("body"))
        .click(function () {
            $("html, body").animate({ scrollTop: 0 }, 120);
        }), $backToTopFun = function () {
            var st = $(document).scrollTop(), winh = $(window).height();
            (st > 0) ? $backToTopEle.show() : $backToTopEle.hide();
            //IE6下的定位
            if (!window.XMLHttpRequest) {
                $backToTopEle.css("top", st + winh - 166);
            }
        };
    $(window).bind("scroll", $backToTopFun);
    $(function () { $backToTopFun(); });
})();

样式设置:

.backToTop {
    display: none;
    background:url(../images/go_top.gif);
    background-repeat:no-repeat;
    background-position:0px 0px;
    width:50px;
    height:50px;
    color: #fff;
    font-size: 12px;
    text-align: center;
    position: fixed;
    _position: absolute;
    right: 2px;
    bottom: 2px;
    _bottom: "auto";
    cursor: pointer;
    opacity: .6;
    filter: Alpha(opacity=60);
}
.backToTop:hover
{
    background:url(../images/go_top.gif);
    background-repeat:no-repeat;
    background-position:0px -100px;
}

 

返回顶部js

标签:返回顶部   style   blog   http   color   io   os   ar   sp   

原文地址:http://www.cnblogs.com/vinsonLu/p/4049869.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!