search
Homephp教程PHP源码Lucky Wheel - Lottery program implemented in jQuery PHP - under improvement

Jump to [1] [Full screen preview]
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>小雨在线网站自营销研究</title>
    <link rel="stylesheet" type="text/css" href="css/style.css"/>
    <!--<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>-->
    <script src="//cdn.bootcss.com/jquery/3.0.0/jquery.min.js"></script>
    <script type="text/javascript" src="js/jQueryRotate.2.2.js"></script>
    <script type="text/javascript" src="js/jquery.easing.min.js"></script>


    <script type="text/javascript">


        $(function () {
            $("#startbtn").click(function () {
                lottery();
            });
        });
        function lottery() {
            $.ajax({
                type: 'POST',
                url: 'data.php',
                dataType: 'json',
                cache: false,
                error: function () {
                    alert('出错了!');
                    return false;
                },
                success: function (json) {
                    $("#startbtn").unbind('click').css("cursor", "default");
                    var a = json.angle; //角度
                    var p = json.prize; //奖项
                    $("#startbtn").rotate({
                        duration: 3000, //转动时间
                        angle: 0,
                        animateTo: 1800 + a, //转动角度
                        easing: $.easing.easeOutSine,
                        callback: function () {
                            var con = confirm('恭喜你,中得' + p + '\n还要再来一次吗?');
                            if (con) {
                                lottery();
                            } else {
                                return false;
                            }
                        }
                    });
                }
            });
        }


    </script>


</head>
<body class="keBody">
<h1 id="小雨在线网站自营销研究">小雨在线网站自营销研究</h1>

<div class="kePublic">
    <!--效果html开始-->
    <div class="demo">
        <div id="disk"></div>
        <div id="start"><img  src="/static/imghwm/default1.png"  data-src="images/start.png"  class="lazy" id="startbtn" alt="Lucky Wheel - Lottery program implemented in jQuery PHP - under improvement" ></div>
    </div>
    <!--效果html结束-->
</div>


</body>
</html>

-----------data.php----------------------------------
<?php
/**
 * Created by 小雨在线
 * User: 飛天
 * Date: 2016/6/22 0022
 * Time: 下午 4:27
 */

$prize_arr = array(
    '0' => array('id' => 1, 'min' => 1, 'max' => 29, 'prize' => '一等奖', 'v' => 1),
    '1' => array('id' => 2, 'min' => 302, 'max' => 328, 'prize' => '二等奖', 'v' => 2),
    '2' => array('id' => 3, 'min' => 242, 'max' => 268, 'prize' => '三等奖', 'v' => 5),
    '3' => array('id' => 4, 'min' => 182, 'max' => 208, 'prize' => '四等奖', 'v' => 7),
    '4' => array('id' => 5, 'min' => 122, 'max' => 148, 'prize' => '五等奖', 'v' => 10),
    '5' => array('id' => 6, 'min' => 62, 'max' => 88, 'prize' => '六等奖', 'v' => 25),
    '6' => array('id' => 7, 'min' => array(32, 92, 152, 212, 272, 332), 'max' => array(58, 118, 178, 238, 298, 358), 'prize' => '七等奖', 'v' => 50)
);



function getRand($proArr)
{
    $result = '';

    //概率数组的总概率精度

    $proSum = array_sum($proArr);

    //概率数组循环
    foreach ($proArr as $key => $proCur) {
        $randNum = mt_rand(1, $proSum);
        if ($randNum <= $proCur) {
            $result = $key;
            break;
        } else {
            $proSum -= $proCur;
        }
    }
    unset ($proArr);

    return $result;
}


foreach ($prize_arr as $key => $val) {
    $arr[$val['id']] = $val['v'];
}

$rid = getRand($arr); //根据概率获取奖项id

$res = $prize_arr[$rid - 1]; //中奖项
$min = $res['min'];
$max = $res['max'];
if ($res['id'] == 7) { //七等奖
    $i = mt_rand(0, 5);
    $result['angle'] = mt_rand($min[$i], $max[$i]);
} else {
    $result['angle'] = mt_rand($min, $max); //随机生成一个角度
}
$result['prize'] = $res['prize'];

echo json_encode($result);



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.