1.0.13 • Published 3 years ago

kelpo-lottery-wheel v1.0.13

Weekly downloads
1
License
MIT
Repository
gitlab
Last release
3 years ago

npm version Greenkeeper badge

lottery-wheel

A library helps you performing a wheel for lottery game. Using anime.js underlying.

Usage

npm install kelpo-lottery-wheel

Or download the latest release.

Then link lottery-wheel.min.js or lottery-wheel.js in your HTML.

<script src="/path/to/lottery-wheel.min.js"></script>

ESM is supported as well.

import Wheel from 'kelpo-lottery-wheel';

Suppose you have an element whose id is 'wheel' in your html file.

<svg id="wheel"></svg>

Then you can do the following to create a wheel:

new Wheel({
  el: document.getElementById('wheel'),

  data: [
    {
      text: 'OVO 50.000',
      color: '#f7c600',
      chance: 30,
    },
    {
      text: 'Lamborgini Ourus',
      color: '#a4cd00',
      chance: 1,
    },
    {
      text: 'OVO 100.000',
      color: '#42a500',
      chance: 19,
    },
    {
      text: 'ToteBag Kelpo',
      color: '#2b9b85',
      chance: 10,
    },
    {
      text: 'OVO 150.000',
      color: '#01a5ce',
      chance: 10,
    },
    {
      text: 'Kaos Kelpo 21',
      color: '#3536c1',
      chance: 7,
    },
    {
      text: 'OVO 200.000',
      color: '#582b9a',
      chance: 7,
    },
    {
      text: 'Mug Kelpo 21',
      color: '#f70063',
      chance: 5,
    },
    {
      text: 'Ovo 500.000',
      color: '#cd0000',
      chance: 5,
    },
    {
      text: 'Sticker Kelpo 21',
      color: '#f76300',
      chance: 6,
    },
  ],
  radius: 300,
  duration: 15000,
  onButtonHover(anime, button) {
    anime({
      targets: button.node,
      scale: 1.2,
      duration: 500,
    });
  },
  onSuccess(data) {
    alert(data.text);
  },
  color: {
    border: '#212121',
    line: '#212121',
    button: '#212121',
  },
  buttonText: 'Mulai',
  buttonWidth: 80,
});

API

Methods

constructor(option)

More for option, see below.

draw()

To manually render the wheel when the draw property is set to false.

const wheel = new Wheel({
  el: document.getElementById('wheel'),
  data: ['Beijing', 'London', 'New York', 'Tokyo'],
  draw: false,
});
setTimeout(() => {
  wheel.draw();
}, 2000);

Options

PropertyDescriptionTypeDefault
elThe element where the wheel mounted. Details.Object-
dataAn array of prizes. Details.Array-
posThe top-left corner of the wheel related to its parent element (the el element).Array0, 0
radiusThe radius of the wheel in px.Number100
buttonTextThe text on the button.String'Draw'
fontSizeThe size of text for prizes.Number(auto generate)
buttonWidthThe width of the button in px.Number50
buttonFontSizeThe size of text on the button.Number(auto generate)
limitThe maxium times the wheel can be run.Number0 (unlimited)
durationHow long will the animation last in millseconds.Number5000
turnThe minimum amount of circles the wheel will turn during the animation.Number4
drawIf true, the wheel will be rendered immediately the instance created. Otherwise, you should call draw to manually render it.Booleantrue
clockwiseIf true, the rotation movement will be clockwise. Otherwise, it will be counter-clockwise.Booleantrue
themeThe color preset to be used. Details.String'default'
imageAllow you to render the wheel using image resources. See image.Object-
colorAn object used to override the color in the current theme. See themesObject-
onSuccessThe callback function called when a prize is drawn successfully. Details.Function-
onFailThe callback function called when trying to draw prize while has already drawn limit times. Details.Function-
onButtonHoverThe function called when the mouse moves over the button. DetailsFunction-

example

The simplest way is to implementation:

<svg id="wheel"></svg>

npm.io

1.0.13

3 years ago

1.0.12

3 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.10

4 years ago

1.0.2

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago