-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathresult.html
176 lines (155 loc) · 4.41 KB
/
result.html
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html>
<html>
<head>
<title>运势结果</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimal-ui">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" type="text/css" href="css/result.css">
<style type="text/css">
#view{
width:100%;
height:100%;
background-size:100% 100%;
z-index: 99;
/*position: relative;*/
position: fixed;
top: 0;
left: 0;
/*right: 0;
bottom: 0;*/
display: flex;
}
#thecanvas{
position: absolute;
top: 0;
left: 0;
z-index: 1;
opacity:0;
}
#finalImg{
position: absolute;
top: 0;
left: 0;
z-index: 500;
opacity: 0;
display: flex;
width: 100%;
}
#content{
/*position: relative;*/
}
.content-button {
z-index: 501
}
.shu{
z-index: 101
}
.share-text{
z-index: 101
}
.lottory{
z-index: 101
}
.imgSrc{
position: absolute;top: 0;
z-index: 1000;
}
</style>
</head>
<body>
<div id="content">
<div id="view">
<img src="img/result0.png" style="width: 100%;height: 100%" class="bc">
<div class="user">
2019年 <span> 用户名 </span> 您的
</div>
</div>
<!-- <div class="imgSrc"></div> -->
<!--分享、保存 -->
<div class="share">
<img src="img/share3.png">
</div>
<div class="content-button"></div>
<!-- <div class="share-text"></div> -->
</div>
<div class="lottory">
<img src="img/start.png" style="width: 100%;z-index: 99" >
</div>
<!-- 真正的抽奖点击处 -->
<div class="real-lottory" style="z-index:501"></div>
<div class="result-mask">
<img src="img/share.png" style="width: 100%">
</div>
<img src="" id="finalImg">
</body>
<script src="js/jquery-2.1.4.js"></script>
<script src="js/base64.js"></script>
<script src="js/canvas2image.js"></script>
<script src="https://cdn.bootcss.com/html2canvas/0.5.0-beta4/html2canvas.js"></script>
<script type="text/javascript">
var height = $("#view").height() || 650;
var width = $("#view").width();
console.log(height,width)
var scale = 2;
function changeBg(callback){
var random = parseInt(Math.random()*5,10);
var sex = sessionStorage.getItem("sex");
$(".share img").attr("src","img/share"+ random + ".png")
console.log(random,sex)
if(random == 2){
if(sex == 1){
random = 5
}
}
$(".bc").attr("src","img/result"+ random + ".png")
callback()
}
$(".content-button").click(function(){
$(".result-mask").show();
})
$(".result-mask").click(function(){
$(".result-mask").hide();
})
function takeScreenshot(callback) {
var canvas = document.createElement("canvas")
canvas.setAttribute('id','thecanvas');
canvas.width = width * 2;
canvas.height = height * 2;
canvas.style.width = width + "px";
canvas.style.height = height + "px";
var context = canvas.getContext("2d");
context.scale(2,2);
console.log('test');
html2canvas(document.getElementById('view'), {
canvas:canvas,
onrendered: function(canvas) {
document.body.appendChild(canvas);
callback()
},
});
// console.log("a完成")
}
$(".real-lottory").click(function(){
console.log("抽奖")
})
$(".save").click(function(e){
setTimeout(canvastoImg(document.getElementsByTagName("canvas")[0],'finalImg'),2000)
})
function canvastoImg(canvas,id){
// console.log(canvas,"b开始")
var image = new Image();
image.src = canvas.toDataURL("image/png");
$("#" + id).attr('src',image.src)
$(".imgSrc").text(image.src)
return image;
}
$(function(){
changeBg(function(){
setTimeout(takeScreenshot(function(){
canvastoImg(document.getElementsByTagName("canvas")[0],'finalImg')
}),2000)
})
})
</script>
</html>