帮助中心
获取牛币
联系我们
关于我们
版权声明
素材牛首页
微博登录
QQ登录
微信扫码登录
注册
登录
新浪微博
QQ登陆
微信登录
热门搜索:
小程序
支付
Java
后台模板
上传
商城模板
jQuery
手机
Thinkphp
微信
Vue.js
首 页
网页特效
整站源码
PHP实例
网站模版
工具箱
常用代码
论坛
游戏源码
资源分享
当前位置:
首页
»
精选常用代码
» JS实现抽奖
JS实现抽奖
浏览:824次
-
评论:1次
-
发布时间:2017-10-18
Html
Css
Js
1
2
3
4
5
16
6
15
7
14
8
13
12
11
10
9
* { margin:0; padding:0; font-size:12px; } body { background-color:#2C1914; font-family:"宋体"; } a img,ul,li { list-style:none; } a { text-decoration:none; outline:none; font-size:12px; } input,textarea,select,button { font-size:100%; } .abs { position:absolute; } .rel { position:relative; } .wrap { min-height:1000px; } .main { height:718px; } .con980 { width:980px; margin:0 auto; } .header { width:100%; height:50px; } .play { background:url(images/fl01.jpg) no-repeat; width:980px; height:625px; padding:22px 0 0 21px; } td { width:187px; height:115px; font-family:"微软雅黑"; background-color:#666; text-align:center; line-height:115px; font-size:80px; } .playcurr { background-color:#F60; } .playnormal { background-color:#666; } .play_btn { width:480px; height:115px; display:block; background-color:#F60; border:0; cursor:pointer; font-family:"微软雅黑"; font-size:40px; } .play_btn:hover { background-position:0 -115px; } .btn_arr { left:255px; top:255px; }
/* * 删除左右两端的空格 */ function Trim(str) { return str.replace(/(^\s*)|(\s*$)/g, ""); } /* * 定义数组 */ function GetSide(m, n) { //获取数组最外圈 var resultArr = []; var tempX = 0, tempY = 0, direction = "Along", count = 0; while (tempX >= 0 && tempX < n && tempY >= 0 && tempY < m && count < m * n) { count++; resultArr.push([tempY, tempX]); if (direction == "Along") { if (tempX == n - 1) tempY++; else tempX++; if (tempX == n - 1 && tempY == m - 1) direction = "Inverse" } else { if (tempX == 0) tempY--; else tempX--; if (tempX == 0 && tempY == 0) break; } } return resultArr; } var index = 0, //当前亮区位置 prevIndex = 0, //前一位置 Speed = 300, //初始速度 Time, //定义对象 arr = GetSide(5, 5), //初始化数组 EndIndex = 0, //决定在哪一格变慢 tb = document.getElementById("tb"), //获取tb对象 cycle = 0, //转动圈数 EndCycle = 0, //计算圈数 flag = false, //结束转动标志 quick = 0; //加速 btn = document.getElementById("btn1"); function StartGame() { clearInterval(Time); cycle = 0; flag = false; EndCycle = 1; Time = setInterval(Star, Speed); EndIndex = Math.floor(Math.random() * 16); } function Star() { //跑马灯变速 if (flag == false) { //走五格开始加速 if (quick == 5) { clearInterval(Time); Speed = 50; Time = setInterval(Star, Speed); } //跑2圈减速 if (cycle == 2) { clearInterval(Time); Speed = 300; flag = true; //触发结束 Time = setInterval(Star, Speed); } } if (index >= arr.length) { index = 0; cycle++; } //结束转动并选中号码 if (flag == true && index == parseInt(`${EndIndex}`) - 1) { quick = 0; clearInterval(Time); } tb.rows[arr[index][0]].cells[arr[index][1]].className = "playcurr"; if (index > 0) prevIndex = index - 1; else { prevIndex = arr.length - 1; } tb.rows[arr[prevIndex][0]].cells[arr[prevIndex][1]].className = "playnormal"; index++; quick++; }
↑上面代码改变,会自动显示代码结果
jQuery调用版本:
1.11.3
<!doctype html><html><head><meta charset="utf-8"><title>JS实现抽奖-www.sucainiu.com</title><script src="https://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script><style>
</style></head><body>
<script>
</script>
</body></html>
立即下载
收藏
积分说明:注册即送10牛币,每日签到可获得5牛币,成为VIP会员可永久免牛币下载!
充值积分
充值会员
更多说明»
代码描述:实现抽奖功能,简单实用
jQuery tab切换内容
HTML5简单的时间选择
讨论这个常用代码(1)
回答他人问题或分享心得会奖励牛币
Lv4 码徒
ok***07
2017年10月19日
有没有关于抽奖算法的讲解?
回复
文明上网,理性发言! 😉 阿里云幸运券,
戳我领取
发表评论
提交回复
我的积分余额:
0
已下载次数:
824
所需牛币:
5
开始下载
牛币获取:
签到、评论、充值
» 在线充值
(10牛币=1元)
成为VIP可永久免积分下载全部常用代码
» 查看详情
VIP
客服
签到
充值