博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
j抽奖
阅读量:7061 次
发布时间:2019-06-28

本文共 1722 字,大约阅读时间需要 5 分钟。

var lottery = { index: 0, //当前转动到哪个位置,起点位置 count: 0, //总共有多少个位置 timer: 0, //setTimeout的ID,用clearTimeout清除 speed: 150, //初始转动速度 times: 0, //转动次数 cycle: 30, //转动基本次数:即至少需要转动多少次再进入抽奖环节 prize: -1, //中奖位置 init: function(id) { if($("#" + id).find(".lottery-unit").length > 0) { $lottery = $("#" + id); $units = $lottery.find(".lottery-unit"); this.obj = $lottery; this.count = $units.length; //$lottery.find(".lottery-unit-" + this.index).addClass("active"); }; }, roll: function() { var index = this.index; var count = this.count; var lottery = this.obj; $(lottery).find(".lottery-unit-" + index).removeClass("active"); index += 1; if(index > count - 1) { index = 0; }; $(lottery).find(".lottery-unit-" + index).addClass("active"); this.index = index; return false; }, stop: function(index) { this.prize = index; return false; } }; function roll() { lottery.times += 1; lottery.roll(); if(lottery.times > lottery.cycle + 10 && lottery.prize == lottery.index) { clearTimeout(lottery.timer); //lottery.prize = -1; lottery.times = 0; lottery.speed = 150; clickFlg = false; lotteryCbk(); } else { if(lottery.times < lottery.cycle) { lottery.speed -= 1; } else if(lottery.times == lottery.cycle) { //var index = Math.random() * (lottery.count) | 0; //lottery.prize = index; } else { if(lottery.times > lottery.cycle + 10 && ((lottery.prize == 0 && lottery.index == 7) || lottery.prize == lottery.index + 1)) { lottery.speed += 110; } else { lottery.speed += 20; } } if(lottery.speed < 40) { lottery.speed = 40; }; lottery.timer = setTimeout(roll, lottery.speed); } return false;}复制代码

转载于:https://juejin.im/post/5bffa44a5188252f170e1bb1

你可能感兴趣的文章
GrooveX研发情感治愈机器人lovot,可与人类完成亲密互动
查看>>
使用kubeadm安装k8s-1.11版本
查看>>
美联邦调查局 FBI 网站被黑,数千特工信息泄露
查看>>
超燃!Apache Flink 全球顶级盛会强势来袭
查看>>
约你一起来写作
查看>>
修改arcgis infowindow 放大和缩小的模板
查看>>
ASP.NET 2.0+Atlas编写鼠标拖放程序(2)
查看>>
JavaScript返回上一页代码区别
查看>>
EntityFramework 如何进行异步化(关键词:async·await·SaveChangesAsync·ToListAsync)
查看>>
百度编辑器ueditor每次编辑后多一个空行的解决办法
查看>>
C#扇形的绘制与Hittest交互、图种制作
查看>>
【MVC 4】5.SportsSore —— 一个真实的应用程序
查看>>
Lucene.Net:构造搜索表达式简化搜索
查看>>
Hadoop - Zeppelin 使用心得
查看>>
Android GIS开发系列-- 入门季(2) MapView与图层介绍
查看>>
爪哇国新游记之二十五----图及其遍历查找
查看>>
Windows Live Writer Technical Preview 公布下载
查看>>
iphone:使用NSFileManager取得目录下所有文件(遍历所有文件)
查看>>
IPK僵尸网络 看看其传播手法
查看>>
Visual Studio DSL 入门 14---用Wix制作安装程序
查看>>