小编给大家分享一下js怎么实现随机数小游戏,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获、下面让我们一起去了解一下吧!
具体内容如下
1, HTML结构代码如下
& lt; div 类=癿ask"比;
,& lt; div 类=癱ontents"比;
& lt;才能div 类=癶ead"比;
,,& lt; p>谁去拿外卖& lt;/p>
,,& lt; a https://www.yisu.com/zixun/href=" # " id="关闭"> X >
<按钮> 按钮>
随机到最小数字的人去拿外卖
<李类=" takeout-list ">扔出了一个2 李>
<李>扔出了一个李> 3
2, css样式代码如下
.mask {,
位置:大敌;固定;左:,0;:,0;
高度,宽度:100%;:,100%;
背景:大敌;rgba (0, 0, 0, 0.5);
}
.contents {
,位置:绝对的,:,54 px;左:,50%;
,宽度:360 px;边界:,1 px solid 灰色;背景:,白色;
,这个特性:5 px;变换:,translateX (-50%);,
}
.head {
,box-sizing: border-box;宽度:,100%;高度:,44 px;
,填充:10 px;边界底部:,1 px solid # eee;,
}
.head p  {
,浮动:左;
}
.head a  {
,浮动:正确的,宽度:,16 px;
,行高:24 px;颜色:,# ccc;
}
.head : hover {
,颜色:蓝色;
}
.cont-wapper {
,宽度:300 px;颜色:,# 555;
,填充:15 px 30 px;保证金:,0,汽车;
}
,.cont-inner {
,字体大小:12 px;背景:,# dbf0fa;
,padding-top: 15 px;保证金:,0,汽车;
,margin-bottom: 10 px;不必:,1 px 1 px 2 px # ddd;
}
,.cont-inner h3  {
高度,宽度:186 px;:, 188 px;保证金:,0,汽车;
背景:大敌;url(& # 39; . ./. ./内容/img1 ico.png& # 39;), 0, -120 px 不再重演;
}
.cont-inner button  {
,显示:块;游标:,指针;/*箭头变手*/,大纲:没有,/*去掉浏览器默认的外边框*/高度,宽度:271 px;:, 40 px;边界:,0;
背景:大敌;url(& # 39; . ./. ./内容/img1 ico.png& # 39;), 0, 0,不再重演;
,保证金:-45 px auto 15 px;
}
,.sign {
,位置:相对;text-align:,中心;
,颜色:# 777;margin-bottom:, 10 px;
}/*后伪元素在元素之后添加内容*//* content 属性与,:before 及,:after 伪元素配合使用,来插入生成内容*/.sign: after {,,
,内容:& # 39;& # 39;;显示:,块;
,位置:绝对的,宽度:,40 px;高度:,7 px;
,背景:# ccc;右:,16 px;:, 5 px;
}/*前伪元素在元素之前添加内容。*//* content 属性与,:before 及,:after 伪元素配合使用,来插入生成内容*/,.sign: before {
,内容:& # 39;& # 39;;显示:,块;位置:,绝对;
高度,宽度:40 px;:, 7 px;
,背景:# ccc;左:,16 px;:, 5 px;
}
,.cont-inner ul  {
,身高:180 px;保证金:,0,10 px;
,填充:5 px 5 px 0, 5 px;
,溢出:隐藏。/*隐藏滚动条*/}
.cont-wapper li.takeout-list  {
,颜色:# fe5a23;粗细:,600;
,高度:19 px;行高:,19 px;
背景:大敌;url(& # 39; . ./. ./内容/img1 ico.png& # 39;), 0, -320 px 不再重演;
}
.cont-wapper li  {
,padding-left: 5 px;
}
3, js代码获取元素
var button =, document.getElementsByTagName(& # 39;按钮# 39;)[0];//按钮
var ullist =, document.getElementsByTagName (& # 39; ul # 39;) [0];
var arrList =,[];//创建数组
var mask =, document.getElementsByClassName(& # 39;面具# 39;)[0];
var text =, document.getElementsByClassName(& # 39;内容# 39;)[0];
var min =,南;//最小值
var 指数;//索引值
4, js代码实现鼠标滑过的时候背景的动态变化
//鼠标按下事件
时间=button.onmousedown function (), {=,this.style.backgroundPosition & # 39; 0, & # 39;, +, (-80), +, & # 39; px # 39;;
,cteatNumer()//调用生成数组的方法
,//鼠标放开事件=,,this.onmouseup  function (), {
时间=this.style.backgroundPosition 才能;& # 39;0,& # 39;,+,(-40),+,& # 39;px # 39;;
,}
};//鼠标移入事件
时间=button.onmouseenter function (), {=,this.style.backgroundPosition & # 39; 0, & # 39;, +, (-40), +, & # 39; px # 39;;
,//鼠标移出事件=,,this.onmouseleave  function (), {
时间=this.style.backgroundPosition 才能;& # 39;0,& # 39;,+,0,+,& # 39;px # 39;;
,}
};