Gadget-BackToTop.js

来自漫画百科
跳转至:导航搜索
/* ------------------------------------------------------------------------------------------- */
/* -- source: http://www.cnblogs.com/ATree/archive/2011/04/09/JQuery_Mootools_Back-Top.html -- */
/* ------------------------------------------------------------------------------------------- */

(function() {
    var $backToTopTxt = "返回顶部", $backToTopEle = $('<div class="backToTop"></div>').appendTo($("body"))
        .text($backToTopTxt).attr("title", $backToTopTxt).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(); });
})();