GithubHelp home page GithubHelp logo

chukwumaijem / roll-a-die Goto Github PK

View Code? Open in Web Editor NEW
49.0 4.0 18.0 767 KB

Simple 3D dice roll using CSS3 animation.

License: MIT License

JavaScript 44.03% HTML 8.32% Less 47.65%
javascript css html animation die dice dice-roller dice-rolls 3d

roll-a-die's Introduction

Roll A Die

npm package

Simple 3D dice roll animator by CSS3 Animation.

Demo

Vanilla JS

Copy dist/roll-a-die.js into your library folder Load it into your HTML script

<script type="text/javascript" src="path/to/roll-a-die.js"></script>

You can use the UNPKG link https://unpkg.com/[email protected]/dist/roll-a-die.js. Remember to update the package number to the most recent.

Call the method with its options.

rollADie({ element, numberOfDice: 2, callback});

With npm (and CommonJS builder)

Install with npm.

npm install --save roll-a-die

Install with yarn.

yarn add roll-a-die

import the library

ES5

const rollADie = require('roll-a-die');

ES6

import rollADie from 'roll-a-die';

Call the method

rollADie({ element, numberOfDice: 2, callback });
rollADie({ element, numberOfDice: 2, callback, soundVolume: 1 });
rollADie({ element, numberOfDice: 2, callback, delay: 1000, soundVolume: 0 }); // disable sound
rollADie({ element, numberOfDice: 2, callback, values: [3, 4], soundVolume: 0.3 });

Parameter Definitions

  • element: The element to render die animation on. Type: HTMLElement
  • numberOfDice: The number of dice to use.` Type: number
  • callback: Called when animation is finished. Returns an array of the values from throw. Type: Function
  • soundVolume: Set volume of audio between 0 and 1. (Optional) Defaults to 1. Type: number
  • delay: Time in milliseconds to delay before removing animations (Optional). Type: number
  • values: Values to show on die face. When provided, it overrides library genrated values. (Optional). Type: Array of numbers

Thanks

License

MIT License

roll-a-die's People

Contributors

alexandrosda007 avatar chukwumaijem avatar dependabot[bot] avatar justincohan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

roll-a-die's Issues

Audio elements don't get removed

When triggering the method rollADie() multiple times it creates new audio elements but doesn't get rid of old ones or reueses them.

Callback is triggered immediately

The provided callback will be executed immediately. It would be great if it is executed after the animation faded.

rollADie({ element, numberOfDice: 1, delay: 3000, callback: () => { console.log("done animating"); }, values: [value] });

Feature Request: Support for customizing svg of dice

Would it be possible to include the feature to provide the SVG markup for the dice in an angular template or by specifying an URL to a SVG-File? I think currently the SVG markup is pretty much hardcoded inside the javascript code and there is just know way to get the hands on it because of minifications and so on ...

Any help would be appreciated! :)

Available only up to version 1.3.1

Hi!

I was trying to use the package but it is only available up to version 1.3.1 instead of the current release 1.5.3, could you fix this please?

Best.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.