The example in this article describes the detailed steps of the dice lottery game implemented by jQuery+PHP. Share it with everyone for your reference. The specific analysis is as follows:
This game is based on the Monopoly game. It uses jQuery and PHP knowledge to design a lottery effect by throwing dice points. Of course, the lottery probability is controllable. Developers can slightly modify this example. It can be applied to the lottery scenario on the website. The rendering is as follows:
Click here to download the complete example code from this website.
HTML part:
First we need to prepare two dice and prize materials. These authors have already packaged and uploaded them, so please feel free to download them. We will write the following html structure code in the html page. .wrap is used to place the dice and prompt information, and #prize is used to place the prize.
We need to use CSS technology to reasonably standardize the page layout. We surround the prizes in a rectangle with 10 positions in total, and position the two dice in the center of the rectangle. You can directly click on the middle dice during the draw. We can use CSS positioning technology to implement page layout.
Copy codejQuery部分:
我们使用jQquery来完成前端动作,包括掷色子动画,仿大富翁奖品逐步运动动画,其中有防重复点击知识、ajax交互知识,动画提示知识。整个 操作流程可简单概括为:点击色子->向dice.php发送ajax请求->完成掷色子动画->提示点数->逐步运动动画到最终 奖品位置停止->完成抽奖。
函数diceroll()是一个色子运动动画,在本站前面的文章中已讲解过,就是通过jQuery的animate()实现的位移、延时、变化背景样式来实现的动画效果。
What dice.php needs to do is: get the total points based on the configured prize probability, distribute the points of the two dice according to the total points, and finally return the points of the two dice to the front-end page.
The function getRand() is used to calculate probability
I hope this article will be helpful to everyone’s PHP programming design.