vue制作抓娃娃机的示例代码

2020-06-16 06:57:38易采站长站整理

去年为联通制作双十一活动,做四个小游戏:‘配对消消乐’、移动拼图、抓娃娃、倒计时。 现在先做来分享一下制作抓娃娃游戏时的经验 先上效果图

游戏规则:在指定时间内抓到上图四张卡片为挑战成功。 现在直接说游戏主要内容:娃娃滚动、爪子向下抓取、抓到卡片 废话不多说直接上代码!(此样式是根据需求而定)


<!--布局样式-->
<div class="game">
<!--爪子-->
<div class="paw">
<div class="pawer"></div>
<div class="pawerPic">
<img src="./../assets/img/zhuashou.png" class="lose" />
<div class="win" v-if="gzShow2">
<img :src="t_img" />
</div>
</div>
</div>
<!--区域-->
<div class="area">
<!--娃娃滚动-->
<div id="pack" ref="pack">
<div id="sel1" class="father" ref="imgs">
<img
v-for="img in imgs"
:class="img.isSuc ? 'yes' : 'no'"
:src="img.img"
:key="img.id"
:alt="img.isSuc"
/>
</div>
</div>
</div>
<span class="button" @click="zhua"></span>
</div>


// css
.game {
width: 80%;
height: 730px;
background: url(./../assets/img/interface_1.png) no-repeat;
background-size: 100%;
animation: bg infinite 0.6s;
position: relative;
top: -60px;
left: 0;
z-index: 2;
.paw {
position: relative;
top: 10%;
}
.pawer {
width: 20px;
background: rgb(170, 219, 254);
height: 10px;
position: absolute;
top: 20px;
left: 51%;
margin-left: -15px;
border-left: 1px solid rgba(42, 59, 156, 0.7);
border-right: 1px solid rgba(42, 59, 156, 0.7);
}
.pawerPic {
width: 95px;
// height:85px;
position: absolute;
top: 30px;
left: 51%;
margin-left: -55px;
img {
width: 100%;
}
.win {
position: absolute;
bottom: -60px;
}
}
.area {
width: 100%;
height: 500px;
// overflow:hidden;
position: absolute;
// top:40px;
left: 0;
bottom: 40px;
}
/*娃娃滚动*/
#pack {
width: 80%;
white-space: nowrap;
overflow: hidden;
position: absolute;
bottom: 60px;
left: 10%;
#sel1 {
display: block;
img {
display: block;
width: 130px;
height: 150px;
float: left;
margin-left: 20px;
}
}
}
.button {
display: block;
width: 130px;