最近做一个抽奖的功能,一开始毫无头绪,不知道随机这个概念,后来找了一堆资料,才慢慢知道这个原理
1、ps圆盘及箭头用于抽奖frontend展示
2、找jquery插件用于旋转箭头,jqueryRotate和jquery.easing,前者就是让图像旋转功能,后者就是让图像运动的效果
3、php端判断是否中奖,用了一个比较简单的方法
$a =array_fill(0,$lottery['first_prize'], 1);
$b = array_fill(0,$lottery['second_prize'], 2);
$c = array_fill(0,$lottery['third_prize'], 3);
$d = array_fill(0,$lottery['four_prize'], 4);
$e = array_fill(0,$lottery['five_prize'], 5);
$arr = array_merge($a, $b, $c, $d, $e);
$total=count($arr);
$luck = $arr[mt_rand(0,$total)];
这样就能控制随机的中奖
4、前端箭头控制
$(this).rotate({
duration: 3000, //转动时间
angle: 0, //起始角度
animateTo: 1440 + radio, //结束的角度
easing: $.easing.easeOutSine, //定义运动的效果,需要引用jquery.easing.min.js的文件
callback: function() { // 回调函数
$("#message_box").text(message);
$("#message_reward").modal('show');
}
});