小編這次要給大家分享的是vue如何制作抓娃娃機,文章內(nèi)容豐富,感興趣的小伙伴可以來了解一下,希望大家閱讀完這篇文章之后能夠有所收獲。
創(chuàng)新互聯(lián)建站專注于興化網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供興化營銷型網(wǎng)站建設(shè),興化網(wǎng)站制作、興化網(wǎng)頁設(shè)計、興化網(wǎng)站官網(wǎng)定制、小程序制作服務(wù),打造興化網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供興化網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
去年為聯(lián)通制作雙十一活動,做四個小游戲:‘配對消消樂'、移動拼圖、抓娃娃、倒計時。 現(xiàn)在先做來分享一下制作抓娃娃游戲時的經(jīng)驗 先上效果圖
游戲規(guī)則:在指定時間內(nèi)抓到上圖四張卡片為挑戰(zhàn)成功。 現(xiàn)在直接說游戲主要內(nèi)容:娃娃滾動、爪子向下抓取、抓到卡片 廢話不多說直接上代碼!(此樣式是根據(jù)需求而定)
<!--布局樣式--> <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> <!--區(qū)域--> <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; height: 90px; background: url(./../assets/img/button.png) no-repeat; background-size: 100%; position: absolute; bottom: 20px; left: 40%; } }
接下來就是卡片滾動,設(shè)置定時器,給卡片模塊設(shè)置transform 讓卡片從右向左勻速移動。
mounted() { this.wawa(); this.talon = $(".pawerPic").offset().left + 100; // 首先獲取爪子的位置(這里是固定的) } wawa() { var pack = this.$refs.pack, width = $("#pack").width(), imgsWidth = (this.imgs.length * width) / 3, initLeft = 0; this.chatTimer = setInterval(function() { initLeft++; if (imgsWidth - initLeft < width + 60) { initLeft = 0; } $("#sel1").css({ width: imgsWidth, transform: "translateX(-" + initLeft + "px)" }); }, 15); },
再接著就是點擊按鈕控制爪子上下移動抓取卡片。 首先固定爪子的位置,上圖代碼中mounted里面的talon,然后設(shè)置爪子到下面的終止距離(差不多能夠到卡片),為爪子設(shè)置動畫改變top值,拉長繩子改變height值(因為爪子和繩子是分開的)。 當(dāng)爪子到達下面時,獲取每個卡片的位置,與爪子當(dāng)前位置作比較,看爪子是否在某個卡片的指定抓取區(qū)域內(nèi)來判斷是否抓到卡片,然后上升。
看完這篇關(guān)于vue如何制作抓娃娃機的文章,如果覺得文章內(nèi)容寫得不錯的話,可以把它分享出去給更多人看到。
網(wǎng)站標(biāo)題:vue如何制作抓娃娃機
文章源于:http://chinadenli.net/article18/ppeogp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、全網(wǎng)營銷推廣、網(wǎng)站內(nèi)鏈、、品牌網(wǎng)站設(shè)計、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)