vuejs可以做轉盤,其實現方法:1、建立抽獎按鈕;2、獲取轉盤應該停止的位置;3、與後臺互動;4、在動畫結束後停在步驟2設定的地方;5、設定提示中獎解鎖功能。
本文操作環境:windows7系統、Vue2.9.6版、Dell G3電腦。
vuejs 可以做轉盤嗎?
Vue中可設定的圓形抽獎轉盤元件
canBeRotated()
裡--①當前擁有的抽獎次數是否大於0②現在是否正在轉動著(被鎖著)),判斷通過則進行下一步, 否則彈出相應提示。turntableStyleOption
屬性)turntable
)rotateCircle
屬性)duringTime
屬性)prizeData
),顯示在每一格轉盤的位置。(計算要根據圓心旋轉的角度getRotateAngle()
方法)rotate
),結束動畫後告訴父元件已停下。import roundTurntable from './components/roundTurntable';
components: { roundTurntable },
<round-turntable ref="roundTurntable" :prizeData="prizeData" :rotateCircle="rotateCircle" :duringTime="duringTime" :turntableStyleOption="turntableStyleOption" @endRotation="endRotation" class="turntable"> <template slot="item" slot-scope="scope"> <p class="turntable-name">{{ scope.item.prizeName }}</p> <p class="turntable-img"> <img :src="scope.item.prizeImg"> </p> </template> </round-turntable>
data() { return { // 轉盤上的獎品資料 prizeData: [ { id: 1, prizeName: '2000元京東券', prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/1.png', }, { id: 2, prizeName: '300元京東券', prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/7.png', }, { id: 3, prizeName: '50個位元幣', prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/3.png', }, { id: 4, prizeName: '50元話費券', prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/4.png', }, { id: 5, prizeName: '100元話費券', prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/5.png', }, { id: 6, prizeName: '100個位元幣', prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/6.png', } ], // 轉動的圈數 rotateCircle: 6, // 轉動需要持續的時間(s) duringTime: 4.5, // 轉盤樣式的選項 turntableStyleOption: { // 背景色 prizeBgColors: ['#AE3EFF', '#4D3FFF', '#FC262C', '#3A8BFF', '#EE7602', '#FE339F'], // 轉盤的外邊框顏色 borderColor: '#199301', }, } }, methods: { // 已經轉動完轉盤觸發的函數 endRotation() { // 提示中獎 alert(`恭喜您獲獎啦,您的獎品是:${this.prizeData[this.prizeIndex].prizeName}`); }, },
.turntable { position: absolute; left: calc(50% - 200px); top: calc(50% - 200px); width: 400px; height: 400px; } .turntable-name { /*background: pink;*/ position: absolute; left: 10px; top: 20px; width: calc(100% - 20px); font-size: 26px; text-align: center; color: #fff; } .turntable-img { position: absolute; /*要居中就要50% - 寬度 / 2*/ left: calc(50% - 80px / 2); top: 60px; width: 80px; height: 80px; img { display: inline-block; width: 100%; height: 100%; } }
引數 | 說明 | 型別 | 預設值 |
---|---|---|---|
ref | 獲取這元件的dom節點,呼叫子元件的開始轉動動畫方法要用到this.$refs[refName].rotate(index) | string | — |
prizeData | 顯示在轉盤上的獎品資料 | array | — |
rotateCircle | 轉盤要轉過的圈數 | number | 6 |
duringTime | 轉動需要持續的時間(單位為秒s ) | number | 4.5 |
turntableStyleOption | 轉盤的樣式選項(背景色、外邊框顏色) | object | { prizeBgColors: ['#AE3EFF', '#4D3FFF', '#FC262C', '#3A8BFF', '#EE7602', '#FE339F'], borderColor: '#199301' } |
class | 用來定義轉盤位置和大小的樣式 | string | — |
事件名稱 | 說明 | 回撥引數 |
---|---|---|
endRotation | 轉盤停下來後觸發的事件回撥 | — |
https://github.com/LiaPig/vue-round-turntable
http://sc.chinaz.com/jiaobendemo.aspx?downloadid=12018113053246
以上就是vuejs 可以做轉盤嗎的詳細內容,更多請關注TW511.COM其它相關文章!