html5抽奖程序,真正的⽹页抽奖-JavaScriptHTML5代码圆盘抽奖
*.{margin:0;padding:0;}
如何下载javascript#elm1{height:40px;background-color:#a00;}
#elm2{height:50px;background-color:#0a0;}
#wrap{position:relative;height:400px;}
#bg{position:absolute;left:0;top:0;}
#cell{position:absolute;left:0;top:0;}
#control{position:absolute;left:430px;top:30px;}
start
end
show
var field = [[0,30],[30,60],[60,90],[90,120],[120,150],[150,180],[180,210],[210,240],[240,270],[270,300],[300,330], [330,360]]
,fillStyle = ['#a00','#0a0','#00a','aa0','#a16','#0aa','#a5a','f31','#784','#a43','#34a','#786']
,width = 400
,height = 400
,c_x = 200
,c_y =200
,radius = 200
,dom_bg = ElementById('bg')
,dom_cell = ElementById('cell')
,index =0
,timer = null
,stop = false
,running = false
,speed = 300
,flag = false
,stepall
,stepfast = 7
,stepslow
,stepping =0
,selected
,pos;
function setup(){
drawBg();
}
function drawBg(){
var deg = Math.PI/180;
var tmp_1 = 0;
var tmp_2 = 30;
dom_bg.height = height;
dom_bg.width = width;
var ctx=Context('2d');
for(var i=0;i<12;i++){
ctx.beginPath();
ctx.fillStyle = fillStyle[i];
ctx.arc(c_x,c_y,radius,deg*tmp_1,deg*tmp_2,false);
ctx.fill();
ctx.fillStyle = '#000';
ctx.fillText(tmp_1,s(deg*(tmp_1+15))*130,200+Math.sin(deg*(tmp_1+15))*130); tmp_1 +=30;
tmp_2 +=30;
}
}
function drawBgText(){
}
function rotate(){
if(!flag && stepping>7){
clearTimer();
speed = 100;
timer = setInterval(rotate,speed);
}
if(flag && stepping > stepslow && stepping
clearTimer();
speed = 300;
timer = setInterval(rotate,speed);
}
if(index ==12){
index = 0;
}
if(flag && stepping == stepall){
clearTimer();
happy();
}
drawCell();
index++;
stepping++;
}
function drawCell(){
var deg = Math.PI/180;
var tmp_1 = field[index][0];
var tmp_2 = field[index][1];
dom_cell.height=height;
dom_cell.width =width;
var ctx=Context('2d');
ctx.beginPath();
ctx.fillStyle = '#eee';
ctx.arc(c_x,c_y,radius,deg*tmp_1,deg*tmp_2,false);
ctx.fill();
}
function createStop(){
selected = Math.floor(Math.random() * 11); //从0-11个数字中选 想zb在这控制⼀下。var circle = Math.floor(Math.random()*3) + 2;
var c_step = circle *12;
var actualIndex = stepping%12;
stepall = selected - actualIndex + c_step;
flag = true;
stepslow = stepall - 7;
stepping = 0;
}
function happy(){
}
function startClick(){
if(running){
return;
}
running= true;
timer = setInterval(rotate,speed);
}
function endClick(){
if(stop){
return;
}
stop = true;
clearTimer();
createStop();
timer = setInterval(rotate,speed);
}
function clearTimer(){
clearInterval(timer);
timer = null;
}
setup();

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。