zoukankan      html  css  js  c++  java
  • 自己寫的 Loading JS插件

    本文為原創文章,轉載請注明出處,謝謝。
    /**
    * @author samkin.yang
    * @version 1.0
    */
    var $_yxj = new SamkinLoading();


    (function($){
    if($){
    $.fn.extend({
    showLoading : function(){
    $_yxj.showLoading($(this).attr("id"));
    },
    hideLoading : function(){
    $_yxj.hideLoading($(this).attr("id"));
    }
    });
    }
    })(jQuery);



    function DomInfo(i,t,l,w,h){
    this.id = i;
    this.offsetTop = t;
    this.offsetLeft = l;
    this.width = w;
    this.height = h;
    };

    function SamkinLoading(){
    this.iconUrlPrix = "";
    this.loading = function(domId){

    };
    this.getLoadingDivInfo = function(domId) {
    var dom = document.getElementById(domId);
    var t=dom.offsetTop;
    var l=dom.offsetLeft;
    var domHeight = dom.clientHeight;
    var domWidth = dom.clientWidth;
    while(dom=dom.offsetParent){
    t+=dom.offsetTop;
    l+=dom.offsetLeft;
    }
    return new DomInfo(domId,t,l,domWidth,domHeight);
    };
    this.createDiv = function(domId){
    var domInfo = this.getLoadingDivInfo(domId);
    var bottomDiv;// = document.createElement("div");

    bottomDiv = document.getElementById("loadingDiv_" + domId);
    if(!bottomDiv) {
    bottomDiv = document.createElement("div");
    bottomDiv.setAttribute("id", "loadingDiv_"+domInfo.id);
    var topDiv = document.createElement("div");
    topDiv.className = "samkin-loading-top-div";
    bottomDiv.appendChild(topDiv);
    document.body.appendChild(bottomDiv);
    }
    // newNode.style.filter =
    // "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=50,finishOpacity=50)";
    // newNode.style.filter = "Alpha(Opacity=50, FinishOpacity=100, Style=1,
    // StartX=0, StartY=0, FinishX=100, FinishY=140)";

    bottomDiv.style.top = domInfo.offsetTop + "px";
    bottomDiv.style.left = domInfo.offsetLeft + "px";
    bottomDiv.style.width = domInfo.width + "px";
    bottomDiv.style.height = domInfo.height + "px";

    bottomDiv.setAttribute("class", "samkin-loading-bottom-div");
    bottomDiv.className = "samkin-loading-bottom-div";
    bottomDiv.style.display = document.getElementById(domInfo.id).style.display;


    // bottomDiv.style.backgroundImage = "url('" + this.iconUrlPrix
    // +"/images/star.gif')";
    /*
    * if(this.isIE()){ //bottomDiv.style.filter =
    * "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=50,finishOpacity=50)";
    * //bottomDiv.style.filter = "Alpha(Opacity=50, FinishOpacity=100,
    * Style=1, StartX=0, StartY=0, FinishX=100, FinishY=140)";
    * bottomDiv.style.filter = "Alpha(Opacity=20)"; } else {
    * bottomDiv.style.opacity = "0.2"; }
    */




    };
    this.isIE = function() {
    if(document.body.addEventListener) // W3C
    {
    return false;
    }
    else if(document.body.attachEvent) // IE
    {
    return true;
    }
    };
    this.showLoading = function(domId){
    /*
    * var dom = document.getElementById("loadingDiv_" + domId); if(dom) {
    * dom.style.display = "block"; } else { var domInfo =
    * this.getLoadingDivInfo(domId); this.createDiv(domInfo); }
    */
    this.createDiv(domId);
    };
    this.hideLoading = function(domId){
    var dom = document.getElementById("loadingDiv_" + domId);
    if(dom) {
    dom.style.display = "none";
    }
    };
    this.createLoadingObj = function(domId){
    return
    };

    this.test = function(domId){
    this.showLoading(domId);
    };
    };

    使用方法,
    如果在引入了jQuery環境下,可以這樣使用:
    顯示遮罩層:$("#id").showLoading();
    去除遮罩層:$("#id").hideLoading();

    如果沒有引入jQuery的時候可以這樣用:
    顯示遮罩層:$_yxj.showLoading('id');
    去除遮罩層:$_yxj.hideLoading('id');
    @CHARSET "BIG5";
    .samkin-loading-bottom-div {
    position: absolute;
    100px;
    height: 60px;
    background-color: black;
    overflow: hidden;
    display: block;
    opacity:0.8;/* w3c */
    filter:alpha(opacity=80);/* ie */
    }

    .samkin-loading-top-div {
    clear:both;
    100%;
    height:100%;
    background: url('images/two-circle.gif') white no-repeat center;
    }

  • 相关阅读:
    Poj 1742 Coins(多重背包)
    Poj 2350 Above Average(精度控制)
    求二进制数中1的个数
    Poj 1659 Distance on Chessboard(国际象棋的走子规则)
    Poj 2411 Mondriaan's Dream(压缩矩阵DP)
    Poj 2136 Vertical Histogram(打印垂直直方图)
    Poj 1401 Factorial(计算N!尾数0的个数——质因数分解)
    poj 2390 Bank Interest(计算本利和)
    Poj 2533 Longest Ordered Subsequence(LIS)
    Poj 1887 Testing the CATCHER(LIS)
  • 原文地址:https://www.cnblogs.com/CHEUNGKAMING/p/4895347.html
Copyright © 2011-2022 走看看