共 9 条评论关于"抽奖转盘代码怎么做"
最新评论
对于抽奖转盘,大家一定不会陌生,我们经常可以在各大网站中看到这样的东西,今天就带着大家一起来了解一下吧。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | <!doctype html> <html><!--根目录节点标签--> <head><!--头部 规定一些信息(提供给浏览器识别运用 用户看不到) 非可视化标签--> <meta charset="utf-8"><!--字符编码:国际编码 gbk gb2312中文编码--> <!--网页文档的三要素--> <title>转盘抽奖系统</title><!--网页文档的标题--> <meta name="keywords" content="抽奖,转盘"><!--提供给搜索引擎搜索网站--> <meta name="description" content="描述:对网页内容的大概的介绍"> <style>/*css样式*/ *{/*通配符:选择到所有的标签元素*/ margin:0;/*外边距*/ padding:0;/*内边距*/ } body{/*标签选择器*/ background:red; } #rotate{/* # id选择器*/ position:relative;/*相对定位:参考物 相对于自己本身的位置定位*/ width:854px; /*宽度*/ height:504px; /*高度*/ background:red url("images/bg1.png");/*背景*/ margin:50px auto;/*上下为50px 左右自动(居中)*/ } .rotateArrow{/* . class类选择器*/ position:absolute;/*绝对定位:相对于拥有定位属性(relative/absolute/fixed)的最近的父元素定位*/ left:180px;/*距离参考物左端的距离*/ top:102px;/*距离参考物上端的距离*/ width:294px; height:294px; background:url("images/arrow.png"); } .userList{ position:absolute; right:40px; top:150px; width:140px; height:320px; overflow:hidden;/*超出隐藏*/ } .userList ul{ position:relative; top:0px; } .userList ul li{ list-style:none;/*去除前面的小黑圆点*/ height:37px; background:url("images/user.png") no-repeat 0px 10px ; line-height:37px;/*行高*/ text-indent:25px;/*文本缩进*/ } .result{ position:absolute; left:128px; top:185px; width:400px; height:120px; background:rgba(0,0,0,0.5);/*red红色 green 绿色 blue蓝色(0-255) a透明度 0-1 */ display:none;/*隐藏*/ } .result p{ line-height:120px; text-align:center;/*文本左右对齐方式*/ color:#fff;/*文本颜色*/ } .result a{ position:absolute; right:0; top:0; width:24px; height:24px; background:url("images/close.png"); } </style> </head> <body><!--可视化标签--> <!--div盒子模型标签 宽度 高度 位置 背景 边框(css样式)--> <div id="rotate"><!--id="自定义的名称" 唯一的(身份证) 命名的规范(见名知意:用有语义的英文单词)--> <div class="rotateArrow"><!--class 可重复的(姓名)--> </div> <div class="userList"> <ul><!--无序列表标签--> <li>1569****851</li> <li>1515****206</li> <li>1550****789</li> <li>1370****627</li> <li>1828****215</li> <li>1589****572</li> <li>1583****825</li> <li>1396****805</li> <li>1332****261</li> <li>1884****863</li> <li>1384****955</li> <li>1897****137</li> <li>1342****973</li> <li>1558****071</li> <li>1554****168</li> <li>1562****018</li> <li>1805****856</li> <li>1354****809</li> <li>1383****364</li> </ul> </div> <div class="result"> <p>恭喜你中奖了</p><!--段落标签--> <a href="javascript:;"></a><!--超链接标签--> </div> </div> <script src="js/jquery.min.js"></script> <script src="js/jquery.rotate.min.js"></script> <script> //什么元素 通过 什么事件 实现 什么效果 var $this;//全局变量 //$(".rotateArrow")获取元素 $(".rotateArrow").click(function(){ //具体实现抽奖的效果 自己封装一个旋转抽奖的方法 $this = $(this);//$(this)谁的事件就指代谁 //生成一个0-7之间的随机数 Math.random()生成一个0-1之间的随机 var num = Math.floor(Math.random()*8); switch (num) { case 0: rotateFun(0,"很遗憾你没有中奖!!"); break; case 1: rotateFun(45,"恭喜你抽中了5元代金卷!!"); break; case 2: rotateFun(90,"恭喜你抽中了1元代金卷!!"); break; case 3: rotateFun(135,"恭喜你抽中了10元代金卷!!"); break; case 4: rotateFun(180,"很遗憾你没有中奖!!"); break; case 5: rotateFun(180,"很遗憾你没有中奖!!!!"); break; case 6: rotateFun(180,"很遗憾你没有中奖!!!!"); break; case 7: rotateFun(180,"很遗憾你没有中奖!!!!"); break; } }); /** *angle 旋转的角度 *txt 抽中之后的文本提示内容 */ function rotateFun(angle,txt){ var n = Math.floor(Math.random()*5) + 4;//4-9 $this.rotate({//旋转方法 angle:0,//旋转的初始位置 duration:5000,//旋转的时间 animateTo:angle + 360*n,//最少旋转4圈+停止的角度 callback:function(){//旋转停止之后再执行什么函数 $(".result").show();//显示 $(".result p").html(txt); } }); } $(".result a").click(function(){ $(".result").hide();//隐藏 }); //中奖用户无缝滚动 setInterval(function(){ //animate自定义动画 $(".userList ul").animate({"top":"-37px"},500,function(){ //当动画执行完成再触发什么函数 $(this).append($(".userList ul li:first"));//把移出去的第一个元素添加到ul的最后面去 $(this).css("top","0px"); }); },1000);//定时器 在1秒钟之后滚动一次 </script> </body> </html> |
这里我们来设置抽奖概率的时候,就应该用后端来设置了,前端设置的值都是可以修改的,所以只能用来展示用。
「梦想一旦被付诸行动,就会变得神圣,如果觉得我的文章对您有用,请帮助本站成长」
上一篇:web前端技术中浮动如何清除
下一篇:js打飞机游戏
最新评论
免费领取学习资料和视频
收到了,你这个网址无法访问呀
评:react中调用 setState 之后发生了什么大佬,都联系不到你人, 那个友链能帮忙换一下不 原 共享博客 http:/...
评:react中调用 setState 之后发生了什么没咋研究,emmm
评:web前端绘制八卦图_超简单教程这个是太极阴阳鱼,不是八卦图。
评:web前端绘制八卦图_超简单教程文章不错
评:宝塔系统面板无法正常显示我采用该方法解决了才发布的教程
评:iview-admin点击路由报错vue-router.esm.js?8c4f:2007 Uncaught (in promise) NavigationDuplicated {_name: "Navi
测试
@超级管理员这个是我测试的信息
@超级管理员这是一条1111
@超级管理员1
这是一条测试信息
1
1111111
3e423 sdf
哈哈哈,鼓励