欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

返回顶部 js

shiping1 的头像
function include_file(file, _type, callback) {
    var _doc = document.getElementsByTagName('head')[0];
    var isIE = navigator.userAgent.toUpperCase().indexOf("MSIE") == -1 ? false : true;
    var _fileObj;
    if (_type == "script") {
        _fileObj = document.createElement('script');
        _fileObj.setAttribute('type', 'text/javascript');
        _fileObj.setAttribute('src', file);
        _doc.appendChild(_fileObj);
        if (!isIE) {
            _fileObj.onload = function () {
                callback()
            }
        }
        else {
            _fileObj.onreadystatechange = function () {
                if (_fileObj.readyState == 'loaded' || _fileObj.readyState == 'complete') {
                    callback()
                }
            }
        }
    }
    else if (_type == "css") {
        _fileObj = document.createElement('link');
        _fileObj.setAttribute('type', 'text/css');
        _fileObj.setAttribute('rel', 'stylesheet');
        _fileObj.setAttribute('href', file);
        _doc.appendChild(_fileObj);
        if (!isIE) {
            callback()
        } else {
            _fileObj.onreadystatechange = function () {
                if (_fileObj.readyState == 'loaded' || _fileObj.readyState == 'complete') {
                    callback()
                }
            }
        }
    }
}
jQuery(document).ready(function ($) {
    //include_file("/Css/fanhuidibu.css", "css", function () {
        //        if (!IsLoads("/js/jquery-1.3.2.min.js")) {
        //            include_file("/js/jquery-1.3.2.min.js", "script", action)
        //        } else {
        //            action()
        //        }
       
        action();
    //})
});
function action() {
    $(document.body).append("<div id=\"roll\" style=\"display:none;\"><div title=\"回到顶部\" id=\"roll_top\"></div></div>");
    $('#roll_top').click(function () {
        $('html,body').animate({ scrollTop: '0px' }, 800)
    });
    $('#ct').click(function () {
        $('html,body').animate({ scrollTop: $('.ct').offset().top }, 800)
    });
    $(window).scroll(function (event) {
//        if ($.browser.ie6) {
//            $('#roll').css('top', $(this).scrollTop() + $(this).height() - 170)
//        }
        if ($(this).scrollTop() > 260) {
            $('#roll').fadeIn()
        } else {
            $('#roll').fadeOut()
        }
    })
}
function IsLoads(src) {
    var isLoaded = false;
    var scripts = document.getElementsByTagName("script");
    for (i = 0; i < scripts.length; i++) {
        if (scripts[i].src && scripts[i].src.indexOf(src) != -1) {
            if (scripts[i].readyState == "loaded" || scripts[i].readyState == "complete") {
                isLoaded = true;
                break
            }
        }
    }
    return isLoaded
}





下面是css 
#roll {
  1. displayblock;
  2. width15px;
  3. margin-right-500px;
  4. positionfixed;
  5. right50%;
  6. top50%;
  7.  
    _margin-right-505px;
  8.  
    _positionabsolute;
  9.  
    _margin-top300px;
  10.  
    _topexpression(eval(document.documentElement.scrollTop));
}

#roll_top {
  1. positionrelative;
  2. cursorpointer;
  3. height72px;
  4. width26px;
  5. backgroundurl(../images/top.gif) no-repeat;
}

普通分类: