enlarge-pic-mobile.js
点击右侧可以直接下载enlarge-pic-mobile.js
源文件👉🏻enlarge-pic-mobile.js
源码如下↓
javascript
function EnlargePicMobile(args) {
var el = args["el"];
var isMask = args.hasOwnProperty("isMask") ? args["isMask"] : true;
var width = ((args["width"] || '90') * window.screen.width) / 100 + "px";
var height = args["height"] ? (((args["height"] || '35') * window.screen.height) / 100 + "px") : args["height"];
var closeColor = args["closeColor"] || 'red';
var imgOpacity = args["imgOpacity"] || 1;
var maskColor = args["maskColor"] || 'gray';
var maskOpacity = args["maskOpacity"] || 0.65;
el.each(function () {
$(this).click(function (e) {
$("#imgBox").remove();
var b = $(this).find("img").size() > 0 ? $(this).find("img") : $(this);
var imgUrl = b.attr("src") || b.text();
var imgBox = "<div id='imgBox'><img src='" + imgUrl + "' width='" + width + (height ? ("' height='" + height) : "") + "'></img><div id='closeBox' title='关闭'>+</div><div>";
$("body").append(imgBox);
$("#imgBox").css({
position: "absolute",
left: "50%",
top: "50%",
transform: "translate(-50%,-50%)",
transition: 'opacity 1s ease',
opacity: 0,
'z-index': 999
}).animate({ opacity: imgOpacity }, 20);
$("#closeBox").css({
"font-size": "64px",
"font-weight": "800",
"color": closeColor,
"text-align": "center",
top: '20px',
transform: "rotate(45deg)",
cursor: "pointer"
}).click(function () {
$("#imgBox").remove();
$("#maskDiv").remove();
});
if (isMask) {
var maskDiv = '<div id="maskDiv"></div>';
$("body").append(maskDiv);
$("#maskDiv").css({
background: maskColor,
position: 'fixed',
left: '0px',
top: '0px',
width: '100%',
height: '100%',
'z-index': 998,
opacity: maskOpacity
}).show("slow");
}
})
})
}
function EnlargePicMobile(args) {
var el = args["el"];
var isMask = args.hasOwnProperty("isMask") ? args["isMask"] : true;
var width = ((args["width"] || '90') * window.screen.width) / 100 + "px";
var height = args["height"] ? (((args["height"] || '35') * window.screen.height) / 100 + "px") : args["height"];
var closeColor = args["closeColor"] || 'red';
var imgOpacity = args["imgOpacity"] || 1;
var maskColor = args["maskColor"] || 'gray';
var maskOpacity = args["maskOpacity"] || 0.65;
el.each(function () {
$(this).click(function (e) {
$("#imgBox").remove();
var b = $(this).find("img").size() > 0 ? $(this).find("img") : $(this);
var imgUrl = b.attr("src") || b.text();
var imgBox = "<div id='imgBox'><img src='" + imgUrl + "' width='" + width + (height ? ("' height='" + height) : "") + "'></img><div id='closeBox' title='关闭'>+</div><div>";
$("body").append(imgBox);
$("#imgBox").css({
position: "absolute",
left: "50%",
top: "50%",
transform: "translate(-50%,-50%)",
transition: 'opacity 1s ease',
opacity: 0,
'z-index': 999
}).animate({ opacity: imgOpacity }, 20);
$("#closeBox").css({
"font-size": "64px",
"font-weight": "800",
"color": closeColor,
"text-align": "center",
top: '20px',
transform: "rotate(45deg)",
cursor: "pointer"
}).click(function () {
$("#imgBox").remove();
$("#maskDiv").remove();
});
if (isMask) {
var maskDiv = '<div id="maskDiv"></div>';
$("body").append(maskDiv);
$("#maskDiv").css({
background: maskColor,
position: 'fixed',
left: '0px',
top: '0px',
width: '100%',
height: '100%',
'z-index': 998,
opacity: maskOpacity
}).show("slow");
}
})
})
}
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
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