您的位置:首页 > Web前端 > JQuery

JQuery插件:遮罩+数据加载中。。。(特点:遮你想遮,罩你想罩)

2014-09-03 15:45 465 查看
在很多项目中都会涉及到数据加载。数据加载有时可能会是2-3秒,为了给一个友好的提示,一般都会给一个【数据加载中。。。】的提示。今天就做了一个这样的提示框。

先去jQuery官网看看怎么写jQuery插件,然后就开始写了。写下来这么一个插件,稍作优化,就在项目中使用了。下面贴的是我写这个插件时的测试图:

<html>
<head>
<script type="text/javascript" src="./jquery-mask/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="./jquery-mask/jquery.mask.js"></script>
<script type="text/javascript">
var helloDiv;
$(function(){
var tbl=$("#tableContent");
for(var i=0; i< 16;i++){
tbl.append('<tr><td width="25%">hello</td><td width="25%">world</td><td width="25%">jquery</td><td width="22%">mask</td></tr>');
}
helloDiv=$("#hello");
helloDiv.openMask('数据加载中。。。');

});

function openMask(){
helloDiv.openMask("数据加载中。。。。");
}

function closeMask(){
helloDiv.closeMask("数据加载中。。。。");
}
</script>
<body>
<div id="hello" style="width:300px; height:400px; background-color:#ACE;">
<table border="1" width="100%" id="tableContent">
</table>
</div>
<input value="open" type="button" onclick="openMask();"><br>
<input type="button" value="close" onclick="closeMask();">
</body>
</head>
</html>


test.html

写这个插件的重点是:计算提示框的位置问题(top, left)、提示框层次问题(z-index)。

要理解这些属性可以看看:CSS位置和布局的相关博客。

源码参见:http://files.cnblogs.com/f1194361820/jquery-mask.zip
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: