jQuery幸运大转盘_jQuery+PHP抽奖程序(上)

来源:https://www.sucaihuo.com/js/19.html 2015-04-04 14:23浏览(15543) 收藏

网上转盘抽奖程序大多是flash完成的,而本文使用jQuery和PHP来实现转盘抽奖程序,为了便于理解,我们分两部分来讲解,本文讲解第一部分,侧重使用jQuery实现转盘的转动效果。第二部分侧重使用PHP后台代码控制抽奖几率并最终实现转盘抽奖,将在下一篇文章中有讲解。
jQuery幸运大转盘_jQuery+PHP抽奖程序(上)
分类:PHP > 抽奖 难易:初级
下载资源 下载积分: 90 积分

首先要准备两张图片,即圆盘和指针,然后我们在#disk来放置圆盘背景图片,在css中控制,用#start来放置指针图片start.png。

<div id="disk"></div>
<div id="start"><img src="images/start.png" id="startbtn" alt="转盘开启"/></div>

CSS指针和圆盘样式如下:

#disk{width:417px; height:417px; background:url(images/disk.jpg) no-repeat} 
#start{width:163px; height:320px; position:absolute; top:46px; left:130px;} 
#start img{cursor:pointer}

接着我们引入jquery.js、旋转插件jQueryRotate.2.2.js及动画easing插件jquery.easing.min.js。easing 教程我们已经讲过了,<a href='http://www.sucaihuo.com/js/18.html' target='_blank'>jQuery Easing动画插件</a>。

<script type = "text/javascript" src = "jquery.js" > </script>
<script type = "text/javascript" src = "jQueryRotate.2.2.js"></script>
<script type = "text/javascript" src = "jquery.easing.min.js"></script>

最后通过jQueryRotate.js旋转插件,我们让指针转起来。

$(function() {
    $("#startbtn").rotate({
        bind: {
            click: function() {
                var random = Math.floor(Math.random() * 360); //生成随机数 
                $(this).rotate({
                    duration: 3000,
                    //转动时间间隔(速度单位ms) 
                    angle: 0,
                    //指针开始角度 
                    animateTo: 3600 + random,
                    //转动角度,当转动角度到达3600+random度时停止转动。
                    easing: $.easing.easeOutSine,
                    //easing动画效果
                    callback: function() { //回调函数 
                        alert('恭喜您,中奖了!');
                    }
                });
            }
        }
    });
});

本文已经前端jQuery转盘转动,下篇文章中将介绍使用PHP来控制抽奖几率,以及完成两者之间的交互,敬请关注。

标签: 抽奖转盘
评论0
头像

系统已开启自动识别垃圾评论机制,识别到的自动封号,下载出错或者资源有问题请联系全栈客服QQ 1915635791

1 2