본문 바로가기

Development

추첨하기 sample

 
 
 
 
<html>
<head>
<title>추첨 V1.0</title>
</head>
<body>
 
<br>
 
<table border=1 cellspacing=0 align=center width=718>
 <tr>
  <td bgcolor='blue' >
  <font color=white size=2>&nbsp;&nbsp; 추첨 1.0</font>
  </td>
  <td width=20 bgcolor='blue' align='center'>
  <font color='white' style='cursor:hand' onclick="window.opener = 'nothing';window.open('', '_parent', '');window.close();"><b>×</b></font>
  </td>
 </tr>
</table>
 
<table border=1 cellspacing=1 align=center>

 <tr>
  <td height=70 colspan=5 bgcolor=gray>&nbsp;</td>
 </tr>
  <tr>
    <td width=138 height=90 align=center>
      <b><div id='name1' style='font-size:30pt'>&nbsp;</div></b>
    </td>
    <td width=138 height=90 align=center>
      <b><div id='name2' style='font-size:30pt'>&nbsp;</div></b>
    </td>
    <td width=138 height=90 align=center>
      <b><div id='name3' style='font-size:30pt'>&nbsp;</div></b>
    </td>
    <td width=138 height=90 align=center>
      <b><div id='name4' style='font-size:30pt'>&nbsp;</div></b>
    </td>
    <td width=138 height=90 align=center>
      <b><div id='name5' style='font-size:30pt'>&nbsp;</div></b>
    </td>
 
 <tr>
  <td height=70 colspan=5 bgcolor=gray>&nbsp;</td>
 </tr>
 
  <tr>
    <td colspan=5 height='60' align='center' bgcolor=#eeeeee><input type='button' style="height:50;font-size:20;" name='start_butt' value='추첨 시작' onclick="clear_box();set_player();rolling(0,1);"></td>
  </tr>
</table>
 
 
 
<script>
var list = new Array(
'User1',
'User2',
'User3',
'User4',
'User5',
'User6',
'User7',
'User8',
'User9',
'User10',
'User11',
'User12',
'User13',
'User14',
'User15',
'User16'
);
 
 
 
 
 
var list_num = list.length;
var pick_count = 5;
var picked_list = new Array(pick_count);
var timeout_id;
 
if(pick_count > list_num){
 pick_count = list_num;
}
 
function set_player(){
 
 for(i=0;i<pick_count;i++){
  var temp_num = Math.round(Math.random()*(list_num-1));
  var doubled = 0;
 
  for(j=0;j<picked_list.length;j++){
   if(temp_num == picked_list[j]){
    doubled = 1;
   }
  }
 
  if(doubled == 1){
   i = i-1;
   continue;
  }
 
  picked_list[i] = temp_num;
  //alert(picked_list[i]);
 
 }
 
}//end of set_player
 
 
 
 
function rolling(k,num){
 if(k < 0){k=0;}
 
 var temp_num = Math.round(Math.random()*(list_num-1));
 var now_obj_name = 'name'+num;
 var now_obj = document.getElementById(now_obj_name)
 
 //now_obj.innerHTML = list[temp_num];
 
 if(k<30){
  now_obj.innerHTML = list[temp_num];
  speed = k*10;
  k=k+1;
  timeout_id = self.setTimeout('rolling('+k+','+num+')',speed);
 }
 else {
  now_obj.innerHTML=list[picked_list[num-1]]
  //now_obj.style.backgroundColor='yellow';
  setTimeout('turn_on(\''+now_obj_name+'\')',300);
  
  if(num < pick_count){
   num = num + 1;
   timeout_id = self.setTimeout('rolling(0,'+num+')',speed);
  }
 }
}
 
function turn_on(now_obj_name){
 var now_obj = document.getElementById(now_obj_name)
 now_obj.style.backgroundColor='yellow';
}
 
function clear_box(){
 if(timeout_id){
  self.clearTimeout(timeout_id);
 }
 name1.innerHTML="&nbsp;";
 name2.innerHTML="&nbsp;";
 name3.innerHTML="&nbsp;";
 name4.innerHTML="&nbsp;";
 name5.innerHTML="&nbsp;";
 
 name1.style.backgroundColor=''
 name2.style.backgroundColor=''
 name3.style.backgroundColor=''
 name4.style.backgroundColor=''
 name5.style.backgroundColor=''
 
}
 
</script>
 
 
 
 
<br>
<br>
 
</body>
</html>