-
Notifications
You must be signed in to change notification settings - Fork 96
/
index.html
51 lines (47 loc) · 1.6 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
<title>Lottery Demo</title>
<style type="text/css">
body{
height:1000px;
}
#lotteryContainer {
position:relative;
width: 300px;
height:100px;
}
#drawPercent {
color:#F60;
}
</style>
</head>
<body>
<button id="freshBtn">刷新彩票</button><label>已刮开 <span id="drawPercent">0%</span> 区域。</label>
<div id="lotteryContainer"></div>
<script src="Lottery.js"></script>
<script>
window.onload = function () {
var lottery = new Lottery('lotteryContainer', '#CCC', 'color', 300, 100, drawPercent);
lottery.init('http://www.baidu.com/img/bdlogo.gif', 'image');
document.getElementById('freshBtn').onclick = function() {
drawPercentNode.innerHTML = '0%';
lottery.init(getRandomStr(10), 'text');
}
var drawPercentNode = document.getElementById('drawPercent');
function drawPercent(percent) {
drawPercentNode.innerHTML = percent + '%';
}
}
function getRandomStr(len) {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < len; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
</script>
</body>
</html>