npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@winman-f2e/lottery-wheel

v0.1.1

Published

A library created by fle-cli.

Downloads

1

Readme

抽奖转盘

转盘抽奖场景

开始安装

$ npm install @winman-f2e/lottery-wheel

如何使用

import LotteryWheel from '@winman-f2e/lottery-wheel'

document.getElementById('root').innerHTML = `
  <div class="container">
    <div class="plate"></div>
    <div class="indicator"></div>
  </div>
`

const prizes = [
  {
    id: 'vip_2',
    name: '2天VIP'
  },
  {
    id: 'coin_2000',
    name: '2000金币'
  },
  {
    id: 'vip_7',
    name: '7天VIP'
  },
  {
    id: 'cash_888',
    name: '888元现金红包'
  },
  {
    id: 'vip_30',
    name: '30天VIP'
  },
  {
    id: 'coupon_66',
    name: '66钻石券'
  }
]

// 转盘转动
const lotteryWheel = new LotteryWheel({
  el: '.plate',
  initDeg: -30,
  prizes
})

// 指针转动
// const lotteryWheel = new LotteryWheel({
//   el: '.indicator',
//   prizes: [prizes[0]].concat(prizes.slice(1).reverse())
// })

document.querySelector('.indicator').addEventListener('click', () => {
  // 伪装转动,等待抽奖结果
  lotteryWheel.mock()

  // 模拟异步请求,获取抽奖结果
  setTimeout(() => {
    let index = Math.floor(Math.random() * 6)
    lotteryWheel.success(prizes[index].id, prize => {
      console.info(prize)
    })
    // lotteryWheel.fail()
  }, 2000)
}, false)

API

LotteryWheel

const lotteryWheel = new LotteryWheel({
  el: '.plate', // 转动的dom节点,dom或字符串
  prizes: [{ id: 'test', name: 'xxx' }], // 奖品列表,要有id,以便查找对应的奖品
  initDeg: 0, // 初始化时的旋转角度
  offsetDeg: 0, // 旋转到结果时需要偏移的角度
  mockSpeed: 5, // 模拟转动的速度,越大越快
  turnNumber: 5, // 获得抽奖结果后,执行旋转动画的圈数
  timingFunction: 'cubic-bezier(0.38, 0.26, 0.25, 1)', // 旋转动画曲线,若需修改,注意尽量和模拟速度保持流畅的衔接,避免出现停顿
  duration: 5000 // 动画过渡时间,单位ms
})

实例方法

  • mock:模拟转动
  • success:获得抽奖结果时执行,参数:
    • prizeId:用于从prizes的id中寻找对应的奖品
    • callback:动画结束后的回调,参数为prize(奖品列表的一项)
  • fail:抽奖失败时调用,转盘会重置到初始状态

环境配置

构建工具

$ npm install -g fle-cli

# yarn
$ yarn global add fle-cli

命令说明

# 本地开发
fle dev

# 代码构建
fle build

查看更多说明: 构建文档