<html lang="en">
<head>
<meta charset="UTF-8">
<style type="text/css">
*{
margin:0;
padding:0;
}
body{
background:#666;
}
table{
background:#666;
margin:30px auto;
}
table tr td{
width:110px;
height:110px;
}
#btn{
width:150px;
height:40px;
line-height:40px;
display:inline-block;
color:#fff;
font-family:"Microsoft Yahei";
background-color:rgb(106,38,19);
position:relative;
border-radius:3px;
cursor:pointer;
top:100px;
}
#btn:hover{
background-color:#481305;
}
.tar{
border:4px solid #660066;
width:108px;
height:108px;
position:absolute;
top:0;
left:0;
}
.Img{
width:120px;
height:160px;
position:absolute;
left:365px;
top:10px;
border:1px solid #666;
border-radius:5px;
background:url("images/mv.jpg");
background-size:cover;
margin-left:-150px;
}
</style>
</head>
<body>
//表格布局
<table border="0" cellpadding="0" cellspacing="1">
<tr>
<td id="td0" style="background:url(images/0.png);background-size:cover;"></td>
<td id="td1" style="background:url(images/1.png);background-size:cover;"></td>
<td id="td2" style="background:url(images/2.png);background-size:cover;"></td>
<td id="td3" style="background:url(images/3.png);background-size:cover;"></td>
<td id="td4" style="background:url(images/4.png);background-size:cover;"></td>
<td id="td5" style="background:url(images/5.png);background-size:cover;"></td>
<td id="td6" style="background:url(images/6.png);background-size:cover;"></td>
</tr>
<tr>
<td id="td19" style="background:url(images/19.png);background-size:cover;"></td>
<td colspan="5" rowspan="3" style="background:#66cc33;text-align:center;position:relative;">
<div id="btn" >開始抽獎</div>
</td>
<td id="td7" style="background:url(images/7.png);background-size:cover;"></td>
</tr>
<tr>
<td id="td18" style="background:url(images/18.png);background-size:cover;"></td>
<td id="td8" style="background:url(images/8.png);background-size:cover;"></td>
</tr>
<tr>
<td id="td17" style="background:url(images/17.png);background-size:cover;"></td>
<td id="td9" style="background:url(images/9.png);background-size:cover;"></td>
</tr>
<tr>
<td id="td16" style="background:url(images/16.png);background-size:cover;"></td>
<td id="td15" style="background:url(images/15.png);background-size:cover;"></td>
<td id="td14" style="background:url(images/14.png);background-size:cover;"></td>
<td id="td13" style="background:url(images/13.png);background-size:cover;"></td>
<td id="td12" style="background:url(images/12.png);background-size:cover;"></td>
<td id="td11" style="background:url(images/11.png);background-size:cover;"></td>
<td id="td10" style="background:url(images/10.png);background-size:cover;"></td>
</tr>
</table>
<div class="tar"></div>
<script src="js/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
var n=0;
change(0,0); //初始化函數,讓tar處于第一個位置
function change(i,time){
var $tar = $('div.tar'); //獲取tar
var offset = $('#td'+(i%20)).offset(); //讓tar的位置跟表格中的某一個框相同
$tar.animate({top:offset.top-2,left:offset.left-2},time); //確定tar的位置
n = i; //儲存當前的i
}
var num = 0;
function move(){
var randomNumber = Math.random(10)*20;//隨機生成0-20之間的數字
randomNumber = Math.ceil(randomNumber)+50;//加上一個50的基數,增加轉的圈數
num = randomNumber; //儲存當前隨機數
var m = n; //把之前儲存的n給到m
for(var i=m;i<randomNumber+m;i++){ //i=m,下一次點擊開始按鈕,tar就不會又從第一個位置開始跑,同時隨機數也要加上m.
change(i,50); //調用
}
}
window.onload = function(){ //dom節點加載完成時給予開始按鈕點擊事件,
btn.onclick = function(){
move(); //調用
btn.onclick = ''; //取消點擊事件
}
}
var t = 0;
var btn = document.getElementById('btn'); //獲取開始按鈕
setInterval(function(){
t++;
if(t%(Math.ceil((num*50/1000)+1))==0){ // num*50/1000等于轉動一次的時間,表示要每過這個時間才能點擊開始按鈕一次。
btn.onclick = function(){
move();
console.log('執行');
btn.onclick = '';
console.log(Math.ceil((num*50/1000)+1))
}
t = 0;
}
},1000)
</script>
</body>
</html>```
h5轉盤游戲
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
推薦閱讀更多精彩內容
- 近期新品除數據飆高的《武道至尊》、美術效果爆棚的《龍女傳奇》外,還有一款產品也十分引人關注,它的設計理念將引領H5...