演示下载地址:http://www.erdangjiade.com/js/545.html
效果图:
效果图:
- 遍历要抽奖人的头像(你可以把要抽奖的人的头像直接放在images文件下面)
- $dir = "images/";
- $img = "";
- if (is_dir($dir)) {
- if ($dh = opendir($dir)) {
- while (($file = readdir($dh)) != false) {
- if ($file <> '' && strlen($file) > 2) {
- $img .= '"' . $file . '",';
- }
- }
- }
- $img = substr($img, 0, ( strlen($img) - 1));
- }
- 若没有头像,可调用webcam在线拍照
- <a href="photo">拍照</a>
- 定义变量
- var alldata = new Array(<?php echo $img; ?>);
- var num = alldata.length - 1;
- var show = $("#show");
- var btn = $("#btn");
- var open = false;
- 抽奖html代码
- <div class="wrap">
- <div class="show" id="show">点击按钮开始抽奖</div>
- <div class="btn">
- <a href="javascript:void(0)" class="start" id="btn">开始抽奖</a>
- </div>
- </div>
- 开始抽奖和停止抽奖js代码
- function run() {
- if (!open) {
- timer = setInterval(change, 30);
- btn.removeClass('start').addClass('stop').text('停止');
- open = true;
- } else {
- clearInterval(timer);
- btn.removeClass('stop').addClass('start').text('开始抽奖');
- open = false;
- }
- }
- btn.click(function() {
- run();
- })
- 随机抽奖
- function change() {
- var randomVal = Math.round(Math.random() * num);
- var prizeName = alldata[randomVal];
- show.html("<img src='images/" + prizeName + "' />");
- }
复制代码
演示下载地址:http://www.erdangjiade.com/js/545.html