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

lottery-turntable

v1.3.6

Published

turntable for lottery

Downloads

4

Readme

抽奖转盘

由于每个抽奖活动的样式都会不一样,因此这个插件只实现了绘画转盘及转盘转动的模块。 点击抽奖按钮,和抽奖转盘的外框则自行实现,可以参考examples里面的例子。

支持IE9以上版本浏览器

示例

示例

安装

npm install lottery-turntable

or

直接下载 https://raw.githubusercontent.com/coffeedeveloper/turntable/master/build/turntable.min.js

接口说明

var turntable = new Turntable({
  size: 320, //转盘尺寸,默认为320
  textSpace: 15, //奖品名称距离转盘边距,默认为15
  imgSpace: 50, //奖品图片距离转盘边距,默认为50
  speed: 5, //触发start事件后,转盘开始转动的速度,数字必须能给360整除
  fastSpeed: 10, //转盘进入高速转动的速度,数字必须能够给360整除
  slowSpeed: 5, //转盘从高速转动降下来的速度,数字必须能够给360整除
  speedUp: 2000, //多少毫秒后进入高速转动
  speedDown: 2000, //触发stop事件后,多少毫秒进入缓速
  values: [], //奖品对象,根据传多少个奖品对象,自动生成相应数量的转盘抽奖内容
  container: document.getElementById('id') //转盘的容器,如果设置了之后,new Turntable的时候会自动填充内容
});

新增支持transition方式

var turntabl = new Turntable({
  type: 'transition', //转盘转动类型
  size: 320, //转盘尺寸,默认为320
  textSpace: 15, //奖品名称距离转盘边距,默认为15
  imgSpace: 50, //奖品图片距离转盘边距,默认为50
  speed: 5, //transition动画持续多长时间,秒为单位
  ring: 8, //转动多少圈后到达终点,越大转速越快
  values: [], //奖品对象,根据传多少个奖品对象,自动生成相应数量的转盘抽奖内容
  container: document.getElementById('id') //转盘的容器,如果设置了之后,new Turntable的时候会自动填充内容
});

turntable的奖品对象说明

var turntable = new Turntable({
  values: [
    {
      id: 1, //奖品id,可以重复(比如:谢谢参与就可以有n个,中奖后会随即选择一个转动到该位置
      name: '一等奖', //奖品名称
      img: {
        src: 'gift.png', //奖品图片路径
        width: 50, //奖品图片宽度,请根据实际情况去设置,避免太大
        height: 50, //奖品图片高度,请根据实际情况去设置,避免太大,与宽度等比率缩放
      },
      bg: '#ccc', //该奖品的在转盘中的扇形背景颜色
      fill: '#000' //奖品名称的文字颜色
    }
  ]
});

turntable事件说明

draw

将转盘实例化到容器当中,如果设置container属性,则不需要调用该方法

turntable.draw(document.getElementById('container'));

start(非transition方式的抽奖)

开始抽奖(开始转动转盘)

turntable.start();

stop(非transition方式的抽奖)

抽奖结束(停止转动转盘)

//id 中奖的奖品id,对应初始化选项里面的values的奖品对象的id
//callback 转盘滚动结束后,触发回调
turntable.stop(id, function(data) {
  console.log(data); //对应在values里面的礼品对象
});

goto(只能用于transition方式的抽奖)

跳转到指定的id的奖品,在请求后台取得中奖奖品id后,就滚动到对应的奖品

//id 中奖的奖品id,对应初始化选项里面的values的奖品对象的id
//callback 转盘滚动结束后,触发回调
turntable.goto(id, function(data) {
  console.log(data); //对应在values里面的礼品对象
});