js锁屏解屏通过对$.ajax进行封装实现

时间:2022-05-06 16:17:34

jquery插件源码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* 对jquery中$.ajax进行封装,以便加入锁屏功能
* isAsync 是否为异步请求,默认为true
* isLock 是否锁屏,默认是true
* isCache 是否从浏览器缓存中加载信息,默认是fasle
***/
;(function($) {
$.fn.doPost = function(settings) {
settings = jQuery.extend({
isAsync:true,
type : "post",
url : null,
dataType : null,
data : null,
success : null,
error : toError,
isLock : true,
isCache : false
}, settings);
$(this).each(function(){
if(settings.isLock){
lockSrc();
}
$.ajax({
async:settings.isAsync,
type:settings.type,
url:settings.url,
dataType:settings.dataType,
data:settings.data,
cache:settings.isCache,
success:function(msg){
if(settings.isLock){
unlockSrc();
}
settings.success(msg);
},
error:settings.error
});
});
 
//锁屏方法
function lockSrc(){
$(".lockDiv").css({"opacity":"0.5"}).fadeIn('normal');
var scrollWidth = document.documentElement.clientWidth;//document.body.clientWidth;
var scrollHeight =document.documentElement.clientHeight; // document.body.clientHeight;
var divWidth = $(".lockDivInfo").width();
var divHeight = $(".lockDivInfo").height();
var divLeft = scrollWidth/2-divWidth/2;
var divTop = scrollHeight/2-divHeight/2;
//console.log("bodyWidth="+scrollWidth+",bodyHeight="+scrollHeight+",divHeight="+divHeight+",divWidth="+divWidth+",left="+divLeft+",top="+divTop);
$(".lockDivInfo").css({"position":"absolute","top":divTop,"left":divLeft}).fadeIn('normal');
}
//解屏方法
function unlockSrc(){
$(".lockDivInfo").fadeOut('normal');
$(".lockDiv").fadeOut('normal');
}
function toError(){
alert("操作失败!");
}
};
})(jQuery);

锁屏样式:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
锁屏
*/
 
.lockDiv {
width: 100%;
height: 100%;
display: none;
z-index: 10;
background-color: #DFE8F6;
position: absolute;
top: 0px;
left: 0px;
}
.lockDivInfo {
width: 50px;
height: 2px;
display: none;
position: absolute;
left: 0px;
top: 0px;
z-index: 11
}
#CloseDiv {
float: right;
width: 100px;
height: 100px;
margin-top: 10px;
margin-right: 10px;
}
?
1
2
3
4
<div class="lockDiv"></div>
<div class="lockDivInfo" >
<img id="CloseDiv" src="/hnhd/images/circle_animation.gif"></img>
</div>

使用方法

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//查询
$("#queryBtn").click(function(){
selecCheckByRegionApp.query();
});
 
var selecCheckByRegionApp={};
selecCheckByRegionApp.query=function(){
var settion={
type:"post",
url: 'selfCheckStatisticAction!findByRegion' ,
dataType:"text",
data:$("#searchForm").formSerialize(),
success:function(msg){
$("#contentDiv").html(msg);
}
};
$("#queryBtn").doPost(settion);
}