微信小程序?qū)崿F(xiàn)簡單的搖骰子游戲
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)搖骰子游戲的具體代碼,供大家參考,具體內(nèi)容如下
頁面代碼
<view class='top'>{{txt}}</view> <view class='point1'> <image src='{{one_img}}'></image> </view> <view class='point2'> <image src='{{two_img}}'></image> <image src='{{three_img}}'></image> </view> <view class='btn' bindtap='enter'>{{msg}}</view>
樣式代碼
.top{ width: 220px; height: 30px; font-size: 25px; margin: 20px auto; } .point1 image,.point2 image{ width: 150px; height: 150px; } .point1 image{ display: block; margin:45px auto; } .point2 image{ margin-top: -20px; margin-left: 25px; } .btn{ width:100%; height:60px; background:green; border-radius: 10px; line-height: 60px; text-align: center; font-size: 30px; margin-top: 60px; }
js代碼
//index.js //獲取應(yīng)用實(shí)例 const app = getApp() Page({ data: { one_img:'../../image/6-point.png', two_img: '../../image/6-point.png', three_img: '../../image/6-point.png', flag:true, timer:null, msg:'搖一搖', total:0, txt:'恭喜你搖到了:0', //圖片的素材和效果圖會(huì)發(fā)在最下面 arr:[ '../../image/1-point.png', '../../image/2-point.png', '../../image/3-point.png', '../../image/4-point.png', '../../image/5-point.png', '../../image/6-point.png', ] }, enter:function(event){ let obj = this; if(obj.data.flag==true){ obj.data.timer = setInterval(function () { let one = Math.floor(Math.random() * 6); let two = Math.floor(Math.random() * 6); let three = Math.floor(Math.random() * 6); obj.setData({ one_img: obj.data.arr[one], two_img: obj.data.arr[two], three_img: obj.data.arr[three], flag:false, msg:'停止', total:one+two+three+3, // total:18, txt:'', }) }, 50); }else{ clearInterval(obj.data.timer); obj.setData({ //one_img: obj.data.arr[5], //two_img: obj.data.arr[5], //three_img: obj.data.arr[5], msg:'搖一搖', flag:true, txt:'恭喜你搖到了:'+obj.data.total, }) } }, })
圖片素材和效果圖
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
查詢綁定數(shù)據(jù)島的表格中的文本并修改顯示方式的js代碼
查詢綁定數(shù)據(jù)島的表格中的文本并修改顯示方式的js代碼2009-12-12JS實(shí)現(xiàn)鼠標(biāo)滑過顯示邊框的菜單效果
這篇文章主要介紹了JS實(shí)現(xiàn)鼠標(biāo)滑過顯示邊框的菜單效果,涉及javascript響應(yīng)鼠標(biāo)事件動(dòng)態(tài)修改頁面元素的相關(guān)操作技巧,需要的朋友可以參考下2016-09-09Threejs實(shí)現(xiàn)滴滴官網(wǎng)首頁地球動(dòng)畫功能
這篇文章主要介紹了Threejs實(shí)現(xiàn)滴滴官網(wǎng)首頁地球動(dòng)畫效果,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-07-07Hammer.js+輪播原理實(shí)現(xiàn)簡潔的滑屏功能
這篇文章主要介紹了Hammer.js+輪播原理實(shí)現(xiàn)簡潔的滑屏功能的相關(guān)資料,需要的朋友可以參考下2016-02-02詳解全棧開發(fā)Vercel數(shù)據(jù)庫存儲(chǔ)服務(wù)
這篇文章主要為大家介紹了全棧開發(fā)Vercel數(shù)據(jù)庫存儲(chǔ)服務(wù)功能使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05JS實(shí)現(xiàn)網(wǎng)頁每隔3秒彈出一次對話框的方法
這篇文章主要介紹了JS實(shí)現(xiàn)網(wǎng)頁每隔3秒彈出一次對話框的方法,涉及JavaScript結(jié)合時(shí)間函數(shù)遞歸調(diào)用的相關(guān)技巧,非常簡單,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11