本文為原創文章,轉載請注明出處,謝謝。
/**
* @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;
width: 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;
width:100%;
height:100%;
background: url('images/two-circle.gif') white no-repeat center;
}

自己寫的 Loading JS插件的更多相关文章

  1. H5页面基于iScroll.js插件实现下拉刷新,上拉加载更多

    前言 在我之前的项目中,页面总是干巴巴的,用户的体验不是特别完美,我也是一直觉得把设计师给到的psd做出来就好,很少考虑用户的感受.我喜欢看不同的App,操作每个步骤,观赏每个能和我互动的交互设计效果 ...

  2. js插件---图片懒加载lazyload

    js插件---图片懒加载lazyload 一.总结 一句话总结:使用异常简单,src里面放加载的图片,data-original里面放原图片,不懂的位置去官网或者github找API就好. 1.laz ...

  3. js插件---Amaze UI dialog如何使用

    js插件---Amaze UI dialog如何使用 一.总结 一句话总结:别人给你列出来的参考手册照着用先 1.在哪里去找插件参考资料或者使用手册(一般位置找不到的时候)? github上面啊,非常 ...

  4. js插件---layer.js使用体验是怎样

    js插件---layer.js使用体验是怎样 一.总结 一句话总结:只有jquery和js,没有css,使用各种弹出层掉用各种函数特别方便,特别简单,特别好用. 引入只需要引入这两个,css都不需要, ...

  5. js插件---jqGrid插件如何使用

    js插件---jqGrid插件如何使用 一.总结 一句话总结:jqdrid还是依赖加js初始化的方式,很多时候插件的问题一般都是引入的css和js的问题,jqgrid里面遇到的问题就是下载包有一些js ...

  6. amazeui学习笔记--js插件(UI增强2)--按钮交互Button

    amazeui学习笔记--js插件(UI增强2)--按钮交互Button 一.总结 1.按钮loading状态: <button type="button" class=&q ...

  7. 【jQuery小实例】js 插件 查看图片

    ---本系列文章所用使用js均可在本博客文件中找到. 像淘宝一样,鼠标放在某一件商品上,展示大图信息,甚至查看图片的具体部位.给人超炫的效果,这种效果实现基于js文件和js插件.大致可以分为三步,添加 ...

  8. 【PC端】jQuery+PHP实现浏览更多内容(jquery.more.js插件)

    参数说明: 'amount' : '10', //每次显示记录数 'address' : 'comments.php', //请求后台的地址 'format' : 'json', //数据传输格式 ' ...

  9. chart.js插件生成折线图时数据普遍较大时Y轴数据不从0开始的解决办法[bubuko.com]

    chart.js插件生成折线图时数据普遍较大时Y轴数据不从0开始的解决办法,原文:http://bubuko.com/infodetail-328671.html 默认情况下如下图 Y轴并不是从0开始 ...

随机推荐

  1. PS/2接口

    ps/2接口标准的发展过程 随着计算机工业的发展,作为计算机最常用输入设备的键盘也日新月异.1981年IBM推出了IBM pc/XT键盘及其接口标准.该标准定义了83键,采用5脚DIN连接器和简单的串 ...

  2. COJ 0343 WZJ的公司(二)

    传送门:http://oj.cnuschool.org.cn/oj/home/problem.htm?problemID=313 试题描述: WZJ的公司放假了!为了保证假期期间公司的安全,WZJ决定 ...

  3. Ubuntu配置ecilpse终端启动

    1. 使用Root用户登陆:但如果要使用root用户登录,必须先为root用户设置密码: (1)打开终端,输入:sudo passwd root 然后enter 此时会提示你输入密码,在passwor ...

  4. HelloSilverlight

    一:输入姓名并选中一个日期,将在下面显示 二:XAML代码 <UserControl x:Class="HelloSilverlight.MainPage" xmlns=&q ...

  5. 寻找INTERIGHT衬衫男神! [复制链接]

    寻找INTERIGHT衬衫男神! - 公告板 - 京东内部论坛 - Powered by Discuz! 寻找INTERIGHT衬衫男神!   [复制链接]

  6. C++ —— 笔记汇总

    导读 本文仅用于记录在个人在使用C++过程中的遇到一些的疑问和概念. 目录 语法和概念基础 常用函数 编程注意 编译问题 拓展链接 1.语法和概念基础 1.块域     2.static 作用域    ...

  7. 如何在Ubuntu 12.04 Server 中安装图形用户界面

    root@ubuntu:~# gedit /etc/environment root@ubuntu:~# gedit /etc/profile ---------------------------- ...

  8. poj 2749 Building roads (二分+拆点+2-sat)

    Building roads Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6229   Accepted: 2093 De ...

  9. rsync+inotify实现服务器之间文件实时同步--转

    之前做了“ssh信任与scp自动传输脚本”的技术文档,此方案是作为公司里备份的方法,但在实际的运行中,由于主服务器在给备份服务器传输的时候,我们的主服务器需要备份的文件是实时.不停的产生的,造成不知道 ...

  10. 27个Jupyter快捷键、技巧(原英文版)

    本文是转发自:https://www.dataquest.io/blog/jupyter-notebook-tips-tricks-shortcuts/ 的一篇文章,先记录在此,等有空时我会翻译成中文 ...