微信小程序?qū)崿F(xiàn)簡(jiǎn)單九宮格抽獎(jiǎng)
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)簡(jiǎn)單九宮格抽獎(jiǎng)的具體代碼,供大家參考,具體內(nèi)容如下
廢話(huà)不多說(shuō),先上樣板圖
代碼就先wxml文件:
<view id="container"> ? <!--左上--> ? <view id="li" class='{{amplification_index===1?"indexli":""}}'> ? ? 一等獎(jiǎng) ? ? <view></view> ? </view> ? <!--上--> ? <view id="li" class='{{amplification_index===2?"indexli":""}}'> ? ? 二等獎(jiǎng) ? ? <view></view> ? </view> ? <!--右上--> ? <view id="li" class='{{amplification_index===3?"indexli":""}}'> ? ? 三等獎(jiǎng) ? ? <view></view> ? </view> ? <!--左--> ? <view id="li" class='{{amplification_index===8?"indexli":""}}'> ? ? 八等獎(jiǎng) ? ? <view></view> ? </view> ? <!--開(kāi)始--> ? <a bindtap="startrolling"> ? ? 開(kāi)始抽獎(jiǎng) ? </a> ? <!--右--> ? <view id="li" class='{{amplification_index===4?"indexli":""}}'> ? ? 四等獎(jiǎng) ? ? <view></view> ? </view> ? <!--左下--> ? <view id="li" class='{{amplification_index===7?"indexli":""}}'> ? ? 七等獎(jiǎng) ? ? <view></view> ? </view> ? <!--下--> ? <view id="li" class='{{amplification_index===6?"indexli":""}}'> ? ? 六等獎(jiǎng) ? ? <view></view> ? </view> ? <!--右下--> ? <view id="li" class='{{amplification_index===5?"indexli":""}}'> ? ? 五等獎(jiǎng) ? ? <view></view> ? </view> ? <p id="pp"></p> </view>
wxss文件:
#container { ? width: 750rpx; ? height: 750rpx; } ? #li, a { ? background: #fff; ? margin: 20rpx; ? border: 1px solid #000000; ? width: 210rpx; ? height: 210rpx; ? box-sizing: border-box; ? display: block; ? float: left; ? text-align: center; ? line-height: 100px; ? position: relative; ? border-radius: 5rpx; } ? a:hover { ? cursor: pointer; ? color: orange; ? font-size: 18px; } ? .active { ? background: red; ? color: #fff; } ? #pp { ? line-height: 32px; ? color: #9a9a9a; ? text-align: center; } ? page view .indexli { ? width: 210rpx; ? height: 210rpx; ? margin-top: 0rpx; ? margin-left: 0rpx; ? margin-bottom: 0rpx; ? margin-right: 0rpx; ? box-sizing: border-box; } ? .indexli view { ? position: absolute; ? width: 190rpx; ? height: 190rpx; ? background: #000000; ? opacity: 0.3; ? left: 0; ? top: 0; ? border:10rpx solid blue; } ? a { ? position: relative; } ? a image { ? width: 100%; ? height: 100%; ? border-radius: 5rpx; } ? a view { ? width: 80rpx; ? height: 80rpx; ? position: absolute; ? font-size: 40rpx; ? color: #fff; ? font-weight: 700; ? line-height: 40rpx; ? margin-left: -40rpx; ? margin-top: -40rpx; ? left: 50%; ? top: 50%; ? } ? .c_title { ? width: 100%; ? text-align: center; ? color: #fff; ? font-size: 20rpx; ? padding-top: 30rpx; } ? .c_title2 { ? color: #fff; ? text-align: center; ? font-size: 40rpx; } ? .c_title3 { ? background: red; ? width: 250rpx; ? margin-left: 250rpx; ? height: 40rpx; ? line-height: 40rpx; ? color: #fff; ? font-size: 20rpx; ? text-align: center; } ? .c_titlr4 { ? background: gold; ? color: red; ? width: 400rpx; ? border-radius: 500rpx; ? text-align: center; ? font-size: 20rpx; ? margin-left: 175rpx; ? margin-top: 10rpx; } ? .b1 { ? margin-left: 20rpx;
js文件
// pages/Lottery/Lottery.js Page({ ? data: { ? ? last_index: 0,//上一回滾動(dòng)的位置 ? ? amplification_index: 0,//輪盤(pán)的當(dāng)前滾動(dòng)位置 ? ? roll_flag: true,//是否允許滾動(dòng) ? ? max_number: 8,//輪盤(pán)的全部數(shù)量 ? ? speed: 300,//速度,速度值越大,則越慢 初始化為300 ? ? finalindex: 5,//最終的獎(jiǎng)勵(lì)距離當(dāng)前的位置!不是最后的幾等獎(jiǎng)! ? ? myInterval: "",//定時(shí)器 ? ? max_speed: 40,//滾盤(pán)的最大速度 ? ? minturns: 8,//最小的圈數(shù)為2 ? ? runs_now: 0//當(dāng)前已跑步數(shù) ? }, ? //開(kāi)始滾動(dòng) ? startrolling: function () { ? ? let _this = this; ? ? //初始化步數(shù) ? ? _this.data.runs_now = 0; ? ? //當(dāng)前可以點(diǎn)擊的狀態(tài)下 ? ? if (_this.data.roll_flag) { ? ? ? _this.data.roll_flag = false; ? ? ? //啟動(dòng)滾盤(pán),注,若是最終后臺(tái)無(wú)返回就不好意思里 ? ? ? _this.rolling(); ? ? } ? }, ? onShow: function () { ? ? this.data.min_height = getApp().globalData.windowheight; ? ? this.setData(this.data); ? }, ? //滾動(dòng)輪盤(pán)的動(dòng)畫(huà)效果 ? rolling: function (amplification_index) { ? ? var _this = this; ? ? this.data.myInterval = setTimeout(function () { _this.rolling(); }, this.data.speed); ? ? this.data.runs_now++;//已經(jīng)跑步數(shù)加一 ? ? this.data.amplification_index++;//當(dāng)前的加一 ? ? //獲取總步數(shù),接口延遲問(wèn)題,所以最后還是設(shè)置成1s以上 ? ? var count_num = this.data.minturns * this.data.max_number + this.data.finalindex - this.data.last_index; ? ? //上升期間 ? ? if (this.data.runs_now <= (count_num / 3) * 2) { ? ? ? this.data.speed -= 30;//加速 ? ? ? if (this.data.speed <= this.data.max_speed) { ? ? ? ? this.data.speed = this.data.max_speed;//最高速度為40; ? ? ? } ? ? } ? ? //抽獎(jiǎng)結(jié)束 ? ? else if (this.data.runs_now >= count_num) { ? ? ? clearInterval(this.data.myInterval); ? ? ? this.data.roll_flag = true; ? ? } ? ? //下降期間 ? ? else if (count_num - this.data.runs_now <= 10) { ? ? ? this.data.speed += 20; ? ? } ? ? //緩沖區(qū)間 ? ? else { ? ? ? this.data.speed += 10; ? ? ? if (this.data.speed >= 100) { ? ? ? ? this.data.speed = 100;//最低速度為100; ? ? ? } ? ? } ? ? if (this.data.amplification_index > this.data.max_number) {//判定!是否大于最大數(shù) ? ? ? this.data.amplification_index = 1; ? ? } ? ? this.setData(this.data); ? ? } })
樣式
color: #fff; font-size: 40rpx;} .b2 { margin-left: 20rpx; color: #fff; font-size: 25rpx;} .b3 { margin-left: 20rpx; color: #fff; font-size: 25rpx;} .b4 { margin-left: 20rpx; color: #fff; font-size: 25rpx;} .b5 { margin-left: 20rpx; color: #fff; font-size: 25rpx;}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 微信小程序?qū)崿F(xiàn)轉(zhuǎn)盤(pán)抽獎(jiǎng)
- 微信小程序開(kāi)發(fā)之大轉(zhuǎn)盤(pán) 仿天貓超市抽獎(jiǎng)實(shí)例
- 微信小程序?qū)崿F(xiàn)走馬燈式抽獎(jiǎng)
- 微信小程序抽獎(jiǎng)組件的使用步驟
- 微信小程序?qū)崿F(xiàn)翻牌抽獎(jiǎng)動(dòng)畫(huà)
- 微信小程序 扭蛋抽獎(jiǎng)機(jī)css3動(dòng)畫(huà)實(shí)現(xiàn)詳解
- 微信小程序?qū)崿F(xiàn)九宮格抽獎(jiǎng)
- 微信小程序?qū)崿F(xiàn)多宮格抽獎(jiǎng)活動(dòng)
- 微信小程序 搖一搖抽獎(jiǎng)簡(jiǎn)單實(shí)例實(shí)現(xiàn)代碼
- 微信小程序轉(zhuǎn)盤(pán)抽獎(jiǎng)的實(shí)現(xiàn)方法
相關(guān)文章
Javascript?中?var?和?let?、const?的區(qū)別及使用方法
ECMAScript 變量是松散類(lèi)型的,意思是變量可以用于保存任何類(lèi)型的數(shù)據(jù),每個(gè)變量只不過(guò)是一個(gè)用于保存任意值的命名占位符,這篇文章主要介紹了Javascript?中?var?和?let?、const?的區(qū)別以及具體使用效果,需要的朋友可以參考下2023-01-01重寫(xiě)JS setTimeout 方法 JavaScript Hook
想要重寫(xiě) setTimeout 方法,發(fā)現(xiàn)有動(dòng)態(tài)引入的js,需要改成自己的js,以下教教大家這個(gè)需求,防止網(wǎng)站被劫持2023-07-07JavaScript實(shí)現(xiàn)網(wǎng)頁(yè)版五子棋游戲
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)網(wǎng)頁(yè)版五子棋游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-07-07使用TS來(lái)編寫(xiě)express服務(wù)器的方法步驟
這篇文章主要介紹了使用TS來(lái)編寫(xiě)express服務(wù)器的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10JS簡(jiǎn)單實(shí)現(xiàn)滑動(dòng)加載數(shù)據(jù)的方法示例
這篇文章主要介紹了JS簡(jiǎn)單實(shí)現(xiàn)滑動(dòng)加載數(shù)據(jù)的方法,涉及javascript事件響應(yīng)及頁(yè)面元素屬性動(dòng)態(tài)操作相關(guān)技巧,需要的朋友可以參考下2017-10-10JavaScript打印網(wǎng)頁(yè)指定區(qū)域的例子
這篇文章主要介紹了JavaScript打印網(wǎng)頁(yè)指定區(qū)域的例子,需要的朋友可以參考下2014-05-05JavaScript實(shí)現(xiàn)無(wú)窮滾動(dòng)加載數(shù)據(jù)
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)無(wú)窮滾動(dòng)加載數(shù)據(jù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05使用ionic(選項(xiàng)卡欄tab) icon(圖標(biāo)) ionic上拉菜單(ActionSheet) 實(shí)現(xiàn)通訊錄界面切換實(shí)例
這篇文章主要介紹了使用ionic(選項(xiàng)卡欄tab) icon(圖標(biāo)) ionic上拉菜單(ActionSheet) 實(shí)現(xiàn)通訊錄界面切換實(shí)例代碼,需要的朋友可以參考下2017-10-10