实例介绍
【实例简介】数字抽奖 和大转盘 实例分享
【实例截图】
【核心代码】
实例一:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>js抽奖</title> <style type="text/css"> *{ margin: 0; padding: 0; font-size:12px;} body{ background-color: #2C1914;font-family:"宋体"; } a img, ul, li { list-style: none; } a{text-decoration:none; outline:none; font-size:12px;} input, textarea, select, button { font-size: 100%;} .abs{ position:absolute;} .rel{ position:relative;} .wrap{ min-height:1000px;} .main{ height:718px; } .con980{ width:980px; margin:0 auto;} .header{ width:100%; height:50px;} .play{ background:url(images/fl01.jpg) no-repeat; width:980px; height:625px; padding:22px 0 0 21px;} td{width:187px; height:115px; font-family:"微软雅黑"; background-color:#666; text-align:center; line-height:115px; font-size:80px; } .playcurr{ background-color:#F60;} .playnormal{ background-color:#666;} .play_btn{ width:480px; height:115px; display:block; background-color:#F60;border:0; cursor:pointer; font-family:"微软雅黑"; font-size:40px;} .play_btn:hover{ background-position:0 -115px;} .btn_arr{ left:255px; top:255px;} </style> </head> <body> <div class="wrap"> <div class="header"></div> <div class="main"> <div class="con980"> <div class="play rel"> <p class="btn_arr abs"><input value="点击抽奖" id="btn1" type="button" onclick="StartGame()" class="play_btn" ></p> <table class="playtab" id="tb" cellpadding="0" cellspacing="1"> <tr> <td>1</td><td>2</td><td>3</td><td>4</td><td>5</td> </tr> <tr> <td>16</td><td></td><td></td><td></td><td>6</td> </tr> <tr> <td>15</td><td></td><td></td><td></td><td>7</td> </tr> <tr> <td>14</td><td></td><td></td><td></td><td>8</td> </tr> <tr> <td>13</td><td>12</td><td>11</td><td>10</td><td>9</td> </tr> </table> </div> </div> </div> </div> <script type="text/javascript"> /* * 删除左右两端的空格 */ function Trim(str){ return str.replace(/(^\s*)|(\s*$)/g, ""); } /* * 定义数组 */ function GetSide(m,n){ //初始化数组 var arr = []; for(var i=0;i<m;i ){ arr.push([]); for(var j=0;j<n;j ){ arr[i][j]=i*n j; } } //获取数组最外圈 var resultArr=[]; var tempX=0, tempY=0, direction="Along", count=0; while(tempX>=0 && tempX<n && tempY>=0 && tempY<m && count<m*n) { count ; resultArr.push([tempY,tempX]); if(direction=="Along"){ if(tempX==n-1) tempY ; else tempX ; if(tempX==n-1&&tempY==m-1) direction="Inverse" } else{ if(tempX==0) tempY--; else tempX--; if(tempX==0&&tempY==0) break; } } return resultArr; } var index=0, //当前亮区位置 prevIndex=0, //前一位置 Speed=300, //初始速度 Time, //定义对象 arr = GetSide(5,5), //初始化数组 EndIndex=0, //决定在哪一格变慢 tb = document.getElementById("tb"), //获取tb对象 cycle=0, //转动圈数 EndCycle=0, //计算圈数 flag=false, //结束转动标志 quick=0; //加速 btn = document.getElementById("btn1") function StartGame(){ clearInterval(Time); cycle=0; flag=false; EndIndex=Math.floor(Math.random()*16); //EndCycle=Math.floor(Math.random()*4); EndCycle=1; Time = setInterval(Star,Speed); } function Star(num){ //跑马灯变速 if(flag==false){ //走五格开始加速 if(quick==5){ clearInterval(Time); Speed=50; Time=setInterval(Star,Speed); } //跑N圈减速 if(cycle==EndCycle 1 && index==parseInt(EndIndex)){ clearInterval(Time); Speed=300; flag=true; //触发结束 Time=setInterval(Star,Speed); } } if(index>=arr.length){ index=0; cycle ; } //结束转动并选中号码 //trim里改成数字就可以减速,变成Endindex的话就没有减速效果了 if(flag==true && index==parseInt(Trim('5'))-1){ quick=0; clearInterval(Time); } tb.rows[arr[index][0]].cells[arr[index][1]].className="playcurr"; if(index>0) prevIndex=index-1; else{ prevIndex=arr.length-1; } tb.rows[arr[prevIndex][0]].cells[arr[prevIndex][1]].className="playnormal"; index ; quick ; } </script> </body> </html>
实例二:
$(function() { var $button = $(".button"), deg = 0, index = 0, $content = $(".content"), height = $content.height(), $pc = $(".pc"); $button.on("click",function() { if($content.is(":animated")) return false; deg = 120; addnewClass(deg,index);//逻辑层分开 }); function addnewClass(deg,index) { $pc.css({ '-moz-transform':'rotate(' deg 'deg)', '-webkit-transform':'rotate(' deg 'deg)', '-ms-transform':'rotate(' deg 'deg)', '-o-transform':'rotate(' deg 'deg)', 'transform':'rotate(' deg 'deg)' }); $content.animate({ bottom:-height, opacity:0 },400,function() { $(this).css("opacity","1") .animate({ bottom:0 },400); }); } });
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论