三个数字抽奖js代码

三个数字抽奖js代码源码下载

看看谁在用

查看文件目录结构

文件大小:0.00M

素材分类: 插件- 其它前端代码

更新时间:2024-02-28

模拟老虎机的抽奖效果,三个数字抽奖js代码
const LuckGame = (function (win, doc) {
            class Luck {
                constructor(obj) {
                    this.setting = {
                        len: 5,  //奖品个数
                        speed: 5000, //滚动时间
                        circle: 5, //循环几圈
                    };
                    this.extend(this.setting, obj);
                    this.$ul = doc.querySelectorAll('.game_wrap ul');
                    this.$height = doc.querySelector('.game_item').offsetHeight;
                    this.setList();
                }
                setList() {
                    //填充li
                    let html = '';
                    for (let n = 0; n < this.setting.circle; n++) {
                        for (let i = 0; i < this.setting.len; i++) {
                            html += '<li>' + i + '</li>'; //图片这里自己添加img以及修改样式
                        };
                    };
                    ;[].forEach.call(this.$ul, (o, i) => {
                        o.innerHTML = html;
                        //设置默认随机显示
                        o.style['transform'] = o.style['-webkit-transform'] = 'translate(0px, -' + Math.floor(Math.random() * this.setting.len) * this.$height + 'px) translateZ(0px)';
                    });
                }
                start(arr, fn) {
                    let that = this, countNum = 0;
                    //开始抽奖
                    ;[].forEach.call(that.$ul, (o, i) => {
                        setTimeout(() => {
                            var y = (arr[i] + that.setting.len * (that.setting.circle - 1)) * that.$height;
                            o.style['-webkit-transition'] = that.setting.speed + 'ms ease';
                            o.style['-webkit-transform'] = 'translate(0px, -' + y + 'px) translateZ(0px)'
                        }, i * 300);
                        o.addEventListener('webkitTransitionEnd', function () {
                            this.style['-webkit-transition'] = '0ms ease';
                            this.style['-webkit-transform'] = 'translate(0px, -' + arr[i] * that.$height + 'px) translateZ(0px)';
                            countNum++;
                            if (countNum == that.$ul.length) {
                                fn && fn();
                            }
                        }, false);
                    })
                }
                extend(n, n1) {
                    for (let i in n1) { n[i] = n1[i] };
                }
            }
            return Luck;
        })(window, document);


        var game = new LuckGame({
            len: 4,
            speed: 3000,
            circle: 5,
        });
        btn.onclick = function () {
            game.start([1, 1, 1], function () {
                alert('恭喜你中奖了')
            })
        }

三个数字抽奖js代码

正在加载文件目录...

ID658489下载了 此素材
风之刀下载了 此素材
从零起…下载了 此素材
Pojin下载了 此素材

也许你还喜欢

  1. jquery钱袋抛出金币特效
  2. jQuery从名单随机抽奖源码
  3. jQuery实现红包雨抽奖特效
  4. js九宫格样式抽奖插件
  5. 年会随机抽奖js特效代码
  6. zepto.js手机端开宝箱动画特效
  7. jquery九宫格抽奖插件luckdraw.js
  8. vuejs年会抽奖代码自定义奖项
浏览器上录音Js代码
  • 标签查找|关于我们|用户协议|格式化工具|bootstrapmb.com 版权所有
  • 背景样式编辑器|按钮样式编辑器|背景动效编辑器|图片布局编辑器