index.html 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="screen-orientation" content="portrait">
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"/>
  7. <title>申泽讲师文化活动抽奖页</title>
  8. <link rel="icon" type="image/x-icon" href="img/favicon.ico" />
  9. <link rel="stylesheet" type="text/css" href="css/reset.css">
  10. <link rel="stylesheet" type="text/css" href="css/wall.css">
  11. <style type="text/css">
  12. body, html {
  13. width: 100%;
  14. height: 100%;
  15. }
  16. .result {
  17. position: absolute;
  18. height: 320px;
  19. width: 100%;
  20. left: 0; top: 50%;
  21. margin-top: -160px;
  22. text-align: center;
  23. padding: 10px;
  24. display: none;
  25. }
  26. .result span {
  27. display: inline-block;
  28. font-size: 25px;
  29. width: 150px;
  30. background: #fff;
  31. line-height: 30px;
  32. color: #000;
  33. margin: 5px;
  34. border-radius: 10px;
  35. box-shadow: 0 5px 10px rgba(0, 0, 0, 0.8);
  36. padding: 10px 0;
  37. }
  38. button, input, optgroup, select, textarea {
  39. color: inherit;
  40. font: inherit;
  41. margin: 0;
  42. border: none;
  43. }
  44. button {
  45. overflow: visible;
  46. }
  47. button, select {
  48. text-transform: none;
  49. }
  50. button, html input[type=button], input[type=reset], input[type=submit] {
  51. -webkit-appearance: button;
  52. cursor: pointer;
  53. }
  54. .pure-button {
  55. display: inline-block;
  56. zoom: 1;
  57. line-height: normal;
  58. white-space: nowrap;
  59. vertical-align: middle;
  60. text-align: center;
  61. cursor: pointer;
  62. -webkit-user-drag: none;
  63. -webkit-user-select: none;
  64. -moz-user-select: none;
  65. -ms-user-select: none;
  66. user-select: none;
  67. -webkit-box-sizing: border-box;
  68. -moz-box-sizing: border-box;
  69. box-sizing: border-box;
  70. }
  71. .pure-button {
  72. font-family: inherit;
  73. font-size: 100%;
  74. padding: .5em 1em;
  75. color: #444;
  76. color: rgba(0,0,0,.8);
  77. border: 0 rgba(0,0,0,0);
  78. background-color: #E6E6E6;
  79. text-decoration: none;
  80. border-radius: 2px;
  81. }
  82. .pure-button:focus {
  83. outline: 0
  84. }
  85. .pure-button-hover, .pure-button:hover, .pure-button:focus {
  86. filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#00000000', endColorstr='#1a000000', GradientType=0);
  87. background-image: -webkit-gradient(linear,0 0,0 100%,from(transparent),color-stop(40%,rgba(0,0,0,.05)),to(rgba(0,0,0,.1)));
  88. background-image: -webkit-linear-gradient(transparent,rgba(0,0,0,.05) 40%,rgba(0,0,0,.1));
  89. background-image: -moz-linear-gradient(top,rgba(0,0,0,.05) 0,rgba(0,0,0,.1));
  90. background-image: -o-linear-gradient(transparent,rgba(0,0,0,.05) 40%,rgba(0,0,0,.1));
  91. background-image: linear-gradient(transparent,rgba(0,0,0,.05) 40%,rgba(0,0,0,.1));
  92. }
  93. .button-success, .button-error, .button-warning, .button-secondary {
  94. color: white;
  95. border-radius: 4px;
  96. text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
  97. }
  98. .button-success {
  99. background: #29DA90;
  100. }
  101. .button-error {
  102. background: rgb(202, 60, 60);
  103. }
  104. .button-warning {
  105. background: #FF6BBA;
  106. }
  107. .button-secondary {
  108. background: #6B8DFF;
  109. }
  110. .tools {
  111. position: absolute;
  112. bottom: 20px;
  113. right: 20px;
  114. text-align: center;
  115. }
  116. .tools .pure-button {
  117. display: inline-block;
  118. margin: 5px;
  119. padding: 10px 0;
  120. text-align: center;
  121. width:50px;
  122. }
  123. .mask {
  124. -webkit-filter:blur(5px);
  125. filter:blur(5px);
  126. }
  127. #main {
  128. -webkit-transition: all 1s;
  129. transition: all 1s;
  130. }
  131. .result-btn {
  132. margin-top: 20px;
  133. text-align: right;
  134. margin-right: 30px;
  135. text-decoration: none;
  136. color: white;
  137. }
  138. </style>
  139. </head>
  140. <body>
  141. <div id="main" class="wall">
  142. <div class="result-btn">
  143. <!-- 右上角获奖名单入口 -->
  144. <a href="./result.html" target="_blank" style="color: aqua;">历史获奖名单</a>
  145. </div>
  146. </div>
  147. <div id="result" class="result">
  148. </div>
  149. <div id="tools" class="tools">
  150. <!-- 选择几个人中奖的按钮 -->
  151. <!-- <button
  152. v-for="value in btns"
  153. @click="onClick(value)"
  154. class="pure-button"
  155. :class="{ 'button-error': selected == value}"
  156. >{{value}}</button> -->
  157. <button
  158. class="pure-button"
  159. @click="toggle"
  160. :class="{'button-secondary': !running,
  161. 'button-success': running}">{{running?'停!':'抽取'}}</button>
  162. <button class="pure-button button-warning" @click="reset">重置</button>
  163. </div>
  164. <script type="text/javascript" src="js/zepto.js"></script>
  165. <script type="text/javascript" src="js/vue.js"></script>
  166. <script type="text/javascript" src="js/tagcanvas.js"></script>
  167. <script type="text/javascript" src="js/member.js"></script>
  168. <script type="text/javascript">
  169. (function(){
  170. var choosed = JSON.parse(localStorage.getItem('choosed')) || {};
  171. console.log(choosed);
  172. var speed = function(){
  173. return [0.1 * Math.random() + 0.01, -(0.1 * Math.random() + 0.01)];
  174. };
  175. var getKey = function(item){
  176. // return item.name + '-' + item.phone;
  177. return item.name;
  178. };
  179. var createHTML = function(){
  180. var html = [ '<ul>' ];
  181. member.forEach(function(item, index){
  182. item.index = index;
  183. var key = getKey(item);
  184. var color = choosed[key] ? '#facc15' : 'white';
  185. html.push('<li><a href="#" style="color: ' + color + ';">' + item.name + '</a></li>');
  186. });
  187. html.push('</ul>');
  188. return html.join('');
  189. };
  190. var lottery = function(count){
  191. var list = canvas.getElementsByTagName('a');
  192. var color = '#facc15';
  193. var ret = member
  194. .filter(function(m, index){
  195. m.index = index;
  196. return !choosed[getKey(m)];
  197. })
  198. .map(function(m){
  199. return Object.assign({
  200. score: Math.random()
  201. }, m);
  202. })
  203. .sort(function(a, b){
  204. return a.score - b.score;
  205. })
  206. .slice(0, count)
  207. .map(function(m){
  208. choosed[getKey(m)] = 1;
  209. list[m.index].style.color = color;
  210. // return m.name + '<br/>' + m.phone; // 弹出人员的姓名和电话
  211. return m.name + '<br/>';
  212. });
  213. localStorage.setItem('choosed', JSON.stringify(choosed));
  214. return ret;
  215. };
  216. var canvas = document.createElement('canvas');
  217. canvas.id = 'myCanvas';
  218. canvas.width = document.body.offsetWidth;
  219. canvas.height = document.body.offsetHeight;
  220. document.getElementById('main').appendChild(canvas);
  221. new Vue({
  222. el: '#tools',
  223. data: {
  224. selected: 1, // 默认选择的抽取人数
  225. running: false,
  226. // btns: [
  227. // // 选择被抽中的人数
  228. // 2, 1
  229. // ]
  230. },
  231. mounted () {
  232. canvas.innerHTML = createHTML();
  233. TagCanvas.Start('myCanvas', '', {
  234. textColour: null,
  235. initial: speed(),
  236. dragControl: 1,
  237. textHeight: 14
  238. });
  239. },
  240. methods: {
  241. reset: function(){
  242. if(confirm('确定要重置么?所有之前的抽奖历史将被清除!')){
  243. localStorage.clear();
  244. location.reload(true);
  245. }
  246. },
  247. onClick: function(num){
  248. $('#result').css('display', 'none');
  249. $('#main').removeClass('mask');
  250. this.selected = num;
  251. },
  252. toggle: function(){
  253. if(this.running){
  254. TagCanvas.SetSpeed('myCanvas', speed());
  255. var ret = lottery(this.selected);
  256. if (ret.length === 0) {
  257. $('#result').css('display', 'block').html('<span>已抽完</span>');
  258. return
  259. }
  260. $('#result').css('display', 'block').html('<span>' + ret.join('</span><span>') + '</span>');
  261. TagCanvas.Reload('myCanvas');
  262. setTimeout(function(){
  263. localStorage.setItem(new Date().toString(), JSON.stringify(ret));
  264. $('#main').addClass('mask');
  265. }, 300);
  266. } else {
  267. $('#result').css('display', 'none');
  268. $('#main').removeClass('mask');
  269. TagCanvas.SetSpeed('myCanvas', [5, 1]);
  270. }
  271. this.running = !this.running;
  272. }
  273. }
  274. });
  275. })();
  276. </script>
  277. </body>
  278. </html>