模仿抽奖转盘,并且用cookie记录历史次数
自己制作了一个模仿抽奖转盘的小游戏,代码比较简单,规则是只有三次抽奖机会,并且浏览器会记录抽奖的次数,

代码如下
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title></title>
<style type="text/css">
* {
margin: 0;
padding: 0
}
#wrap {
width: 420px;
height: 420px;
margin-top: 30px;
position: absolute;
left: 200px;
background: url(img/turnplate-bg.png);
border-radius: 50%;
}
#ul1 {
width: 420px;
height: 420px;
margin-top: 30px;
position: absolute;
left: 200px;
border-radius: 50%;
list-style: none;
}
#ul1 li{
width: 8px;height: 418px;
position: absolute;left: 207px;top: 3px;
}
#point{
width: 10px;height: 10px;background: red;
font-size: 12px;color: red;border-radius: 50%;
position: absolute;top: 2px;left: -1px;
box-shadow: 0px 0px 20px white;
animation: move1 1s linear infinite;
}
#box {
width: 400px;
height: 400px;
background: url(img/prize.png);
background-size: 100%;
position: absolute;
transform: rotate(18deg);
left: 10px;
top: 10px;
}
#handle {
width: 136px;
height: 136px;
position: absolute;
left: 143px;
top: 141px;
transition: all 5s ease-out;
z-index: 4;
}
#img1 {
width: 136px;
height: 222px;
position: absolute;
top: -44px;
}
#history{
width: 600px;
height: 400px;
border: 1px solid green;
position: absolute;
top: 30px;left: 700px;
}
#title{
font-size: 20px;
color: green;
width: 160px;
margin: 0 auto;
border-bottom: 1px solid green;
}
#num{font-size: 30px;color: red;}
@keyframes move1{
0%{background: yellow;}
25%{background: red;}
50%{background: green;}
75%{background: blue;}
100%{background: yellow;}
}
</style>
</head>
<body>
<div id="wrap">
<div id="box">
</div>
<div id="handle">
<img src="img/turnplate-pointer.png" id="img1" />
</div>
</div>
<ul id="ul1">
</ul>
<div id="history">
<div id="title">
你已经抽奖<span id="num"></span>次
</div>
<div id="">
<br/><br/><br/><br/>
实现要求:<hr /> <br/><br/>1、有且仅有3次抽奖机会;<br/><br/> 2、开始抽奖,指针随机转5-10圈(每圈360deg,即转的度数为1800-3600之间任意数);<br/> <br/>3、要求把抽奖次数记录下来,把页面关掉重新打开依然有效;
</div>
</div>
</body>
</html>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
var arr = ['30M流量包', '100M流量包', '2闪币', '50M流量包', '10闪币',
'谢谢参与', '5闪币', '10M流量包', '20M流量包', '20闪币']
//定义随机度数
function randFun(max, min) {
return parseInt(Math.random() * (max - min) + min)
}
//显示抽奖次数
$('#num').html(numFun());
//防止多次点击
var lock1 = true,
lock2 = false,
lock3 = false;
//每次随机的转圈度数
var index1 = randFun(1800, 3600);
var index2 = randFun(index1+1800, index1+3600);
var index3 = randFun(index2+1800, index2+3600);
//第一次点击
$('#handle').on('click', function() {
if(lock1) {
lock1 = false;
$('#handle')[0].style.transform = 'rotate(' + index1 + 'deg)';
var a = Math.ceil((index1 % 360) / 36);
setTimeout(function() {
alert(arr[a - 1])
lock2 = true;
if(!document.cookie){
document.cookie = '抽奖次数=1';
$('#num').html(numFun());
}else{
var sum = Number(numFun())+1;
document.cookie = '抽奖次数='+sum;
$('#num').html(numFun());
}
}, 5000)
}
})
//第二次点击
$('#handle').on('click', function() {
if(lock2) {
lock2 = false;
$('#handle')[0].style.transform = 'rotate(' +index2 + 'deg)';
var b = Math.ceil((index2 % 360) / 36);
setTimeout(function() {
alert(arr[b - 1]);
lock3 = true;
var sum = Number(numFun())+1;
document.cookie = '抽奖次数='+sum;
$('#num').html(sum)
}, 5000)
}
})
//第三次点击
$('#handle').on('click', function() {
if(lock3) {
lock3 = false;
$('#handle')[0].style.transform = 'rotate(' +index3 + 'deg)';
var c = Math.ceil((index3 % 360) / 36);
setTimeout(function() {
alert(arr[c - 1]);
var sum = Number(numFun())+1;
document.cookie = '抽奖次数='+sum;
$('#num').html(sum)
$('#handle').on('click',function(){
alert('你的抽奖次数已用尽,请充100元钱获得一次抽奖机会?');
})
}, 5000)
}
})
//闪光灯
function lightsFun(){
for(var i = 0;i < 24;i++){
$('#ul1').append('<li><div id="point"></div></li>');
}
var lis = $('#ul1 li');
for(var j = 0;j<lis.length;j++){
lis[j].style.transform = 'rotate('+j*15+'deg)';
}
}
lightsFun()
//获取cookie数值
function numFun(){
return document.cookie.split('=')[1];
}
</script>
模仿抽奖转盘,并且用cookie记录历史次数的更多相关文章
- cookie记录浏览记录
cookie记录浏览记录 HashMap也是我们使用非常多的Collection,它是基于哈希表的 Map 接口的实现,以key-value的形式存在.在HashMap中,key-value总是会当做 ...
- cookie记录用户的浏览商品的路径
在电子商务的网站中,经常要记录用户的浏览路径,以判断用户到底对哪些商品感兴趣,或者哪些商品之间存在关联. 下面将使用cookie记录用户的浏览过的历史页面.该网站将每个页面的标题保存在该页面的$TIT ...
- 利用java实现抽奖转盘(着重安全控制)
本文是针对jquery 实现抽奖转盘作者的一个补充(主要用java去实现转盘结果生成及存储,解决jquery 做法 非法用户采用模拟器实现改变转盘值的风险性),针对jQuery的具体实现,请看案例:h ...
- android仿漫画源码、抽奖转盘、Google相册、动画源码等
Android精选源码 android实现仿今日头条的开源项目 波浪效果,实现流量的动态显示 美妆领域的app, 集成了摄像头取色, 朋友圈, 滤镜等 android仿漫画源码 android一个视差 ...
- 用CSS实现一个抽奖转盘
效果 基本是用CSS实现的,没有用图片,加一丢丢JS.完全没有考虑兼容性. 首先画一个转盘, <!DOCTYPE html> <html lang="en"> ...
- cookie记录用户名
在说如何用cookie记录用户名之前,我们先来说说cookie的工作原理: cookie : 存储数据,当用户访问了某个网站(网页)的时候,我们就可以通过cookie来像访问者电脑上存储数据 ; 1. ...
- history 清空历史记录 或 history不记录历史命令
# vi ~/.bash_history 清空里面的记录,并退出当前shell # exit(一定要退出当前shell) # history 1 vi ~/.bash_history 2 histor ...
- Android实现抽奖转盘
一.SurfaceView认识及的应用的思路 SurfaceView继承自(extends)View,View是在UI线程中进行绘制: 而SurfaceView是在一个子线程中对自己进行绘制,优势:避 ...
- jquery实现抽奖转盘
用jquery通过配置参数实现抽奖转盘 1.html代码 <!DOCTYPE html> <html lang="zh-CN"> <head> ...
随机推荐
- 数字转化为汉字,如5->五
//数字转化为汉字 如5-->五-(NSString*)translation:(NSString *)arebic{ NSString *str = arebic; NSArray ...
- mysql5.7.26 基于GTID的主从复制环境搭建
简单工作原理: (1)从库执行 change master to 语句,会立即将主库信息记录到master.info中 (2)从库执行 start slave语句,会立即生成IO_T和SQL_T (3 ...
- Python---函数参数---王伟
#### 定义函数 ```python#定义函数def function(): print("hello world")#调用函数function() #输出结果hello ...
- Python 正则表达式Ⅱ
re.search方法 re.search 扫描整个字符串并返https://www.xuanhe.net/回第一个成功的匹配. 函数语法: 函数参数说明: 匹配成功re.search方法返回一个匹配 ...
- sql2014 日志太大 删除日志
首先,我们要确认日志的文件名,因为硬盘上的文件名不一定是数据字典里面的文件名,所以要确认下 USE test9572 GO SELECT file_id,name FROM sys.database_ ...
- yum 源的搭建
repos和epel的关系 https://blog.csdn.net/fantaxy025025/article/details/84918199 配置阿里云的yum源 https://www.cn ...
- 2018中国大学生程序设计竞赛 - 网络选拔赛 Find Integer
Find Integer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
- 51 Nod 1486 大大走格子
1486 大大走格子 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 160 难度:6级算法题 收藏 关注 有一个h行w列的棋盘,里面有一些格子是不 ...
- BZOJ 1488 Luogu P4727 [HNOI2009]图的同构 (Burnside引理、组合计数)
题目链接 (Luogu) https://www.luogu.org/problem/P4727 (BZOJ) https://www.lydsy.com/JudgeOnline/problem.ph ...
- react-router-dom 实现左侧导航
1.介绍react-router-dom https://reacttraining.com/react-router/web/example/basic 这个官网有很多栗子可以练手 1.1 Hash ...