At the end of the year, various companies had lottery activities. I also wrote a super simple code to achieve the lucky draw effect. there was no gorgeous Css3 effect, but there was a short and concise js code. Core: js Math objects and Array objects
Random Award list
Prize received
Start drawingScript/** idea: random lottery, draw an award to reduce a * Math object method: http://www.w3school.com.cn/jsref/jsref_obj_math.asp *-random (): return 0 ~ A random number between 1. *-Floor (): returns an integer * array operation: *-splice (x, y); x: start position, y: number of retrieved and deleted */function random (min, max) {return Math. floor (min + Math. random () * (max-min);} var awardListDom = document. getElementById ("awardListDom"), num = document. getElementById ("num"), submit = document. getElementById ("submit"); var awardList = ["first prize", "Second Prize", "Second Prize", "Third Prize", "Third Prize", "Encouragement Award ", "Encouragement Award", "Thank you for participating", "Thank you for participating ", "Thank you for participating"]; awardListDom. value = awardList; submit. onclick = function () {// reference array var oldArray = awardList; var rNum = random (0, oldArray. length); if (oldArray. length <1) {awardListDom. value = "activity ended"; num. value = "activity ended";} else {num. value = oldArray [rNum]; oldArray. splice (rNum, 1); awardListDom. value = oldArray;} script
Demo: http://demo.jb51.net/js/2015/choujiang/
Github: https://github.com/litengdesign/award