網站首頁 編程語言 正文
H5移動端大轉盤抽獎插件, 簡單、易用、無依賴。
效果:
step 1: 引入資源
<canvas id="lottery" width="300" height="300"></canvas>
<button id="handler">開始抽獎</button>
<!-- Lottery Javascript file -->
<script src="Lottery.js"></script>
step 2: 調用Lottery
new Lottery(document.getElementById('lottery'), {
handler: document.getElementById('handler'),
handlerCallback: function(_interface){
/*ajax獲取中獎結果*/
_ajax(function(response){
/*指定停止的位置:索引*/
_interface.stop(response.index, function(){
console.log('恭喜你中得:' + response.name)
});
});
},
products: [
{
text: '小米電視',
imgUrl: 'http://www.host.com/img1.png'
},
{
text: '華為手機',
imgUrl: 'http://www.host.com/img2.png'
}
...
]
});
構造函數 Lottery 的全部配置項.
var _lottery = new Lottery(document.getElementById('lottery'),{
/*點擊抽獎元素*/
handler: '',
/*點擊抽獎的回調*/
handlerCallback: function(_interface){},
outerRadius: '',
innerRadius: 0,
/*循環填充數組顏色*/
fillStyle: ['#ffdf8a', '#fffdc9'],
/*重復觸發的間距時間*/
interval: 1000,
/*速度越大越快*/
speed: 12,
/*運動最少持續時間*/
duration: 3000,
/*字體位置與樣式*/
/*畫布顯示縮放比例,值為1 安卓模糊*/
scale: this.ua.isIos ? 1 : 4,
/*字體樣式,淺拷貝 需整個font對象傳入*/
font: {
y: '50%',
color: '#ee6500',
style: 'normal',
weight: 500,
size: '12px',
lineHeight: 1,
family: 'Arail'
},
/*圖片位置與尺寸*/
images: {
y: '88%',
width: 32,
height: 32
},
/*打斷文字換行*/
breakText: ['金幣', '紅包'],
/*禮物*/
products: [
/*{
imgUrl: 'http://',
text: '蘋果手機',
}*/
]
});
/*指定停止位置, index為索引 0-products.length */
_lottery.stop(index, function(){
});
源碼地址:https://github.com/huanggengzhong/Big-turntable
原文鏈接:https://blog.csdn.net/xiaodi520520/article/details/104922757
相關推薦
- 2023-12-15 Linux系統——退出vi編輯模式
- 2022-12-15 Python利用pythonping處理ping的示例詳解_python
- 2022-06-25 Python制作簡易計算器功能_python
- 2023-11-13 matplotlib按照論文要求繪圖并保存pdf格式
- 2022-10-27 Windows?Server?2019?安裝后的一些設置收集_win服務器
- 2023-05-10 python中使用numpy包的向量矩陣相乘np.dot和np.matmul實現_python
- 2022-03-06 C#中List用法介紹詳解_C#教程
- 2023-02-07 GoLang?sync.Pool簡介與用法_Golang
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支