抽奖转盘

<!DOCTYPE html>
<html lang="zh-cn">

    <head>
        <meta charset="UTF-8">
        <script type="text/javascript" src="jquery-2.1.4.min.js"></script>
        <title>转盘抽奖</title>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <style type="text/css">
            * {
                padding: 0px;
                margin: 0px;
                font-size: 16px;
                font-family: "Microsoft YaHei";
            }

            .turnplate_box {
                width: 300px;
                height: 300px;
                margin: 100px auto;
                position: relative;
                border: 1px solid red;
            }

            .turnplate_box canvas {
                position: absolute;
                border: 1px solid yellow;
            }

            #myCanvas {
                background-color: white;
                border-radius: 100%;
            }

            #myCanvas01,
            #myCanvas03 {
                left: 50px;
                top: 50px;
                z-index: 30;

            }

            #myCanvas02 {
                left: 75px;
                top: 75px;
                z-index: 20;
            }

            #myCanvas {
                -o-transform: transform 6s;
                -ms-transform: transform 6s;
                -moz-transform: transform 6s;
                -webkit-transform: transform 6s;
                transition: transform 6s;
                -o-transform-origin: 50% 50%;
                -ms-transform-origin: 50% 50%;
                -moz-transform-origin: 50% 50%;
                -webkit-transform-origin: 50% 50%;
                transform-origin: 50% 50%;
            }

            .turnplatw_btn {
                width: 60px;
                height: 60px;
                left: 120px;
                top: 120px;
                border-radius: 50%;
                position: absolute;
                cursor: pointer;
                border: none;
                background: transparent;
                outline: none;
                z-index: 40;
                border: 1px solid red;
            }
        </style>

        <script type="text/javascript">
            $(document).ready(function() {
                //旋转角度
                var angles;
                //可抽奖次数
                var clickNum = 5;
                //旋转次数
                var rotNum = 0;
                //中奖公告
                var notice = null;
                //转盘初始化

                var color = ["red", "green", "blue", "darkblue", "black", "yellow"];//转盘,转盘,内园,字颜色,开始抽奖颜色,开始抽奖背景颜色
                var info = ["谢谢参与", "  1000", "   10", "  500", "  100", " 4999", "    1", "   20"];
                var info1 = ['再接再厉', '      元', '    万元', '  淘金币', '  万美元', '  淘金币', '  日游(月球)', '  个美女']
                canvasRun();
                $('#tupBtn').bind('click', function() {
                    alert(1);
                    if (clickNum >= 1) {
                        //可抽奖次数减一
                        clickNum = clickNum - 1;
                        //转盘旋转
                        runCup();
                        //转盘旋转过程“开始抽奖”按钮无法点击
                        $('#tupBtn').attr("disabled", true);
                        //旋转次数加一
                        rotNum = rotNum + 1;
                        //“开始抽奖”按钮无法点击恢复点击
                        setTimeout(function() {
                            alert(notice);
                            $('#tupBtn').removeAttr("disabled", true);
                        }, 6000);
                    } else {
                        alert("亲,抽奖次数已用光!");

                    }
                });
                //转盘旋转
                function runCup() {
                    probability();
                    var degValue = 'rotate(' + angles + 'deg' + ')';
                    $('#myCanvas').css('-o-transform', degValue); //Opera
                    $('#myCanvas').css('-ms-transform', degValue); //IE浏览器
                    $('#myCanvas').css('-moz-transform', degValue); //Firefox
                    $('#myCanvas').css('-webkit-transform', degValue); //Chrome和Safari
                    $('#myCanvas').css('transform', degValue);
                }
                //各奖项对应的旋转角度及中奖公告内容
                function probability() {
                    //获取随机数
                    var num = parseInt(Math.random() * (7 - 0 + 0) + 0);
                    //概率
                    if (num == 0) {
                        angles = 2160 * rotNum + 1800;
                        notice = info[0] + info1[0];
                    }
                    //概率
                    else if (num == 1) {
                        angles = 2160 * rotNum + 1845;
                        notice = info[7] + info1[7];
                    }
                    //概率
                    else if (num == 2) {
                        angles = 2160 * rotNum + 1890;
                        notice = info[6] + info1[6];
                    }
                    //概率
                    else if (num == 3) {
                        angles = 2160 * rotNum + 1935;
                        notice = info[5] + info1[5];
                    }
                    //概率
                    else if (num == 4) {
                        angles = 2160 * rotNum + 1980;
                        notice = info[4] + info1[4];
                    }
                    //概率
                    else if (num == 5) {
                        angles = 2160 * rotNum + 2025;
                        notice = info[3] + info1[3];
                    }
                    //概率
                    else if (num == 6) {
                        angles = 2160 * rotNum + 2070;
                        notice = info[2] + info1[2];
                    }
                    //概率
                    else if (num == 7) {
                        angles = 2160 * rotNum + 2115;
                        notice = info[1] + info1[1];
                    }
                }
                //绘制转盘
                function canvasRun() {
                    var canvas = document.getElementById('myCanvas');
                    var canvas01 = document.getElementById('myCanvas01');
                    var canvas03 = document.getElementById('myCanvas03');
                    var canvas02 = document.getElementById('myCanvas02');
                    var ctx = canvas.getContext('2d');
                    var ctx1 = canvas01.getContext('2d');
                    var ctx3 = canvas03.getContext('2d');
                    var ctx2 = canvas02.getContext('2d');
                    createCircle();
                    createCirText();
                    initPoint();
                    //外圆
                    function createCircle() {
                        var startAngle = 0; //扇形的开始弧度
                        var endAngle = 0; //扇形的终止弧度
                        //画一个8等份扇形组成的圆形
                        for (var i = 0; i < 8; i++) {
                            startAngle = Math.PI * (i / 4 - 1 / 8);
                            endAngle = startAngle + Math.PI * (1 / 4);
                            ctx.save();
                            ctx.beginPath();
                            ctx.arc(150, 150, 100, startAngle, endAngle, false);
                            ctx.lineWidth = 120;
                            if (i % 2 == 0) {
                                ctx.strokeStyle = color[0];
                            } else {
                                ctx.strokeStyle = color[1];
                            }
                            ctx.stroke();
                            ctx.restore();
                        }
                    }
                    //各奖项
                    function createCirText() {
                        ctx.textAlign = 'start';
                        ctx.textBaseline = 'middle';
                        ctx.fillStyle = color[3];
                        var step = 2 * Math.PI / 8;
                        for (var i = 0; i < 8; i++) {
                            ctx.save();
                            ctx.beginPath();
                            ctx.translate(150, 150);
                            ctx.rotate(i * step);
                            ctx.font = " 20px Microsoft YaHei";
                            ctx.fillStyle = color[3];
                            ctx.fillText(info[i], -30, -115, 60);
                            ctx.font = " 14px Microsoft YaHei";
                            ctx.fillText(info1[i], -30, -95, 60);
                            ctx.closePath();
                            ctx.restore();
                        }
                    }

                    function initPoint() {
                        //箭头指针
                        ctx1.beginPath();
                        ctx1.moveTo(100, 24);
                        ctx1.lineTo(90, 62);
                        ctx1.lineTo(110, 62);
                        ctx1.lineTo(100, 24);
                        ctx1.fillStyle = color[5];
                        ctx1.fill();
                        ctx1.closePath();
                        //中间小圆
                        ctx3.beginPath();
                        ctx3.arc(100, 100, 40, 0, Math.PI * 2, false);
                        ctx3.fillStyle = color[5];
                        ctx3.fill();
                        ctx3.closePath();
                        //小圆文字
                        ctx3.font = "Bold 20px Microsoft YaHei";
                        ctx3.textAlign = 'start';
                        ctx3.textBaseline = 'middle';
                        ctx3.fillStyle = color[4];
                        ctx3.beginPath();
                        ctx3.fillText('开始', 80, 90, 40);
                        ctx3.fillText('抽奖', 80, 110, 40);
                        ctx3.fill();
                        ctx3.closePath();
                        //中间圆圈
                        ctx2.beginPath();
                        ctx2.arc(75, 75, 75, 0, Math.PI * 2, false);
                        ctx2.fillStyle = color[2];
                        ctx2.fill();
                        ctx2.closePath();
                    }
                }
            });
        </script>
    </head>

    <body>
        <div class="turnplate_box">
            <canvas id="myCanvas" width="300px" height="300px">抱歉!浏览器不支持。</canvas>
            <canvas id="myCanvas01" width="200px" height="200px">抱歉!浏览器不支持。</canvas>
            <canvas id="myCanvas03" width="200px" height="200px">抱歉!浏览器不支持。</canvas>
            <canvas id="myCanvas02" width="150px" height="150px">抱歉!浏览器不支持。</canvas>
            <button id="tupBtn" class="turnplatw_btn"></button>
        </div>
        <!-- 更改系统默认弹窗 -->
        <script type="text/javascript">
            window.alert = function(str) {
                var shield = document.createElement("DIV");
                shield.id = "shield";
                shield.style.position = "absolute";
                shield.style.left = "50%";
                shield.style.top = "50%";
                shield.style.width = "280px";
                shield.style.height = "150px";
                shield.style.marginLeft = "-140px";
                shield.style.marginTop = "-110px";
                shield.style.zIndex = "25";
                var alertFram = document.createElement("DIV");
                alertFram.id = "alertFram";
                alertFram.style.position = "absolute";
                alertFram.style.width = "280px";
                alertFram.style.height = "150px";
                alertFram.style.left = "50%";
                alertFram.style.top = "50%";
                alertFram.style.marginLeft = "-140px";
                alertFram.style.marginTop = "-110px";
                alertFram.style.textAlign = "center";
                alertFram.style.lineHeight = "150px";
                alertFram.style.zIndex = "300";
                strHtml = "<ul style=\"list-style:none;margin:0px;padding:0px;width:100%\">\n";
                strHtml += " <li style=\"background:#626262;text-align:left;padding-left:20px;font-size:14px;font-weight:bold;height:25px;line-height:25px;border:1px solid #F9CADE;color:white\">[中奖提醒]</li>\n";
                strHtml += " <li style=\"background:#787878;text-align:center;font-size:12px;height:95px;line-height:95px;border-left:1px solid #F9CADE;border-right:1px solid #F9CADE;color:#DCC722\">" + str + "</li>\n";
                strHtml += " <li style=\"background:#626262;text-align:center;font-weight:bold;height:30px;line-height:25px; border:1px solid #F9CADE;\"><input type=\"button\" value=\"确 定\" onclick=\"doOk()\" style=\"width:80px;height:20px;background:#626262;color:white;border:1px solid white;font-size:14px;line-height:20px;outline:none;margin-top: 4px\"/></li>\n";
                strHtml += "</ul>\n";
                alertFram.innerHTML = strHtml;
                document.body.appendChild(alertFram);
                document.body.appendChild(shield);
                this.doOk = function() {
                    alertFram.style.display = "none";
                    shield.style.display = "none";
                }
                alertFram.focus();
                document.body.onselectstart = function() {
                    return false;
                };
            }
        </script>
    </body>

</html>

时间: 2024-07-30 10:17:25

抽奖转盘的相关文章

利用java实现抽奖转盘(着重安全控制)

本文是针对jquery 实现抽奖转盘作者的一个补充(主要用java去实现转盘结果生成及存储,解决jquery 做法 非法用户采用模拟器实现改变转盘值的风险性),针对jQuery的具体实现,请看案例:http://www.cnblogs.com/mofish/archive/2013/01/24/2875516.html              本文就不一一细说了,那么现在就直入正题. 由于公司产品推广,最近要求实现一个邀请用户注册即可抽奖的转盘,页面展示如下: java 实现方式如下: 构造实

一个简单的抽奖转盘游戏

在一个项目中要做一个游戏,在这个过程中做了一个简单的9宫格抽奖游戏.大体思路是,点击开始按钮,游戏开始.由一个逐步递增参数 drawStep 来控制格子的背景颜色的改变,游戏停止的位置参数 stopPosition 由随机函数生成,以此来控制格子停止的位置.游戏转动一圈是8个格子,5圈就是40.easeTime参数模拟格子转动的缓步启动和缓步停止. <!doctype html> <html> <head> <meta charset="gbk"

利用canvas实现抽奖转盘

之前做过的项目中,有需要抽奖转盘功能的.项目已经完工一段时间了,也没出现什么严重的bug,所以现在拎出来分享给大家. 功能需求 转盘要美观,转动效果流畅. 转盘上需要显示奖品图片,并且奖品是后台读取的照片和名字. 转动动画完成后要有相应提示. 获取的奖品具体算法在数据库里操作,前端只提供最后的效果展示. 知识要点 引用了一个jq插件:awardRotate,用来实现更智能化的转动(插件下载:http://www.jqcool.net/jquery-jqueryrotate.html). 使用ca

模仿抽奖转盘,并且用cookie记录历史次数

自己制作了一个模仿抽奖转盘的小游戏,代码比较简单,规则是只有三次抽奖机会,并且浏览器会记录抽奖的次数, 代码如下 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-sca

九宫格抽奖转盘源码分析

效果如上图所示,下面对其实现代码进行分析,看能不能破解其抽奖规则.需要引入jquery-1.8.3.min.js和images/9张图片. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.or

Android实现抽奖转盘

慕课网视频 今天学习了以下抽奖转盘的实现 首先学习了以下 SurfaceView 的一般使用方法 下面的代码是 写 SurfaceView 的一个模板 package com.negro.myluckypan; import android.content.Context; import android.graphics.Canvas; import android.util.AttributeSet; import android.view.SurfaceHolder; import andr

css 如何“画”一个抽奖转盘

主要描述的是如何运用 css 绘制一个抽奖转盘,并运用原生 js 实现转盘抽奖效果. 先来张效果图: 布局 一般来说,转盘一般有四个部分组成:外层闪烁的灯.内层旋转的圆盘.圆盘上的中奖结果.指针. 所以html的结构如下: <div class="turntable-wrap"> <div class="light" id="turntable_light"></div> <div class="

利用canvas实现抽奖转盘---转载别人的

功能需求 转盘要美观,转动效果流畅. 转盘上需要显示奖品图片,并且奖品是后台读取的照片和名字. 转动动画完成后要有相应提示. 获取的奖品具体算法在数据库里操作,前端只提供最后的效果展示. 知识要点 引用了一个jq插件:awardRotate,用来实现更智能化的转动(插件下载:http://www.jqcool.net/jquery-jqueryrotate.html). 使用canvas标签和对应的html5 api 进行操作.(canvas中文手册可以查看http://javascript.r

iOS 抽奖转盘 练习demo

组里到了新的6+,为了搞一轮抽奖写了这个抽奖程序.是哒我们就是如此调皮~ 首先我们要有权重数据,最近在看权利的游戏,给喜欢的人物加分: 1 NSDictionary *dataDic = [NSDictionary 2 dictionaryWithObjectsAndKeys: 3 @(1),@"Jamie", 4 @(1),@"Cersei", 5 @(1),@"Joffery", 6 @(3),@"Imp", 7 @(1)

Android SurfaceView实战 打造抽奖转盘

转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/41722441 ,本文出自:[张鸿洋的博客] 1.概述 今天给大家带来SurfaceView的一个实战案例,话说自定义View也是各种写,一直没有写过SurfaceView,这个玩意是什么东西?什么时候用比较好呢? 可以看到SurfaceView也是继承了View,但是我们并不需要去实现它的draw方法来绘制自己,为什么呢? 因为它和View有一个很大的区别,View在UI线程去