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