-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchoujian.html
168 lines (155 loc) · 5.05 KB
/
choujian.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>2019抽奖程序</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://lib.baomitu.com/lodash.js/4.14.1/lodash.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
.list-complete-item {
transition: all 1s;
display: inline-block;
border: 1px solid #ccc;
width: 80px;
height: 80px;
line-height: 80px;
text-align: center
}
.draw-bg {
background-color: red;
transform: scale(1.5)
}
.list-complete-enter,
.list-complete-leave-to {
opacity: 0;
transform: translateY(30px);
}
.list-complete-leave-active {
position: absolute;
}
.draw {
height: 100px;
}
button {
padding: 5px 10px;
margin: 20px;
}
li {
float: left
}
.draw-list span {
display: inline-block;
padding: 10px;
background: red;
color: #fff
}
</style>
</head>
<body>
<div id="list-complete-demo" class="demo">
<button v-on:click="start">start</button>
<button v-on:click="end">end</button>
<div class="draw-list">
<span v-for="item in target">{{item}}</span>
</div>
<transition-group name="list-complete" tag="p">
<span v-for="item in arrList" v-bind:key="item" class="list-complete-item" :class="{'draw-bg': item == value}">
{{ item }}
</span>
</transition-group>
</div>
<script>
new Vue({
el: '#list-complete-demo',
data: {
arrList: [
"张三",
"李四",
"王五",
"赵六",
"陈七",
"张扒",
"李十四",
"王十五",
"赵十六",
"陈十七",
"张二三",
"李二四",
"王二五",
"赵二六",
"陈二七",
"张二扒",
"李三四",
"王三五",
"赵三六",
"陈三七"
],
target: [],
index: -1,
timer: null,
value: '',
status: true
},
mounted() {
if (!localStorage.getItem('initData')) {
localStorage.setItem('initData', JSON.stringify(this.arrList))
} else {
this.arrList = JSON.parse(localStorage.getItem('initData'))
}
if (localStorage.getItem('drawList')) {
this.target = JSON.parse(localStorage.getItem('drawList'))
}
},
methods: {
start() {
if (this.status) {
if (this.index != -1) {
this.arrList.splice(this.index, 1)
localStorage.setItem('initData', JSON.stringify(this.arrList))
}
this.shuffle()
setTimeout(() => {
this.recursive()
}, 800)
this.status = !this.status
}
},
randomIndex: function() {
this.index = Math.floor(Math.random() * this.arrList.length)
return this.index
},
remove: function() {
this.arrList.splice(this.randomIndex(), 1)
},
shuffle: function() {
this.arrList = _.shuffle(this.arrList)
},
recursive() {
clearTimeout(this.timer)
this.timer = setTimeout(() => {
this.value = this.arrList[this.randomIndex()]
this.recursive()
}, 200)
},
end() {
if (this.status) {
return
}
clearTimeout(this.timer)
this.index = this.randomIndex()
this.value = this.arrList[this.index]
this.target.push(this.value)
localStorage.setItem('drawList', JSON.stringify(this.target))
this.status = !this.status
}
}
})
</script>
</body>
</html>