Git Product home page Git Product logo

scratchcard's Introduction

ScratchCard

This is a library for turning canvas elements on your web site into "scratchable" objects. You can also set a required percentage of space to be revealed for the task to be completed.

Prerequisites

  • canvas elements with background images that need to be hidden
  • all canvas elements need to have an ID to select them
  • a browser with a working .bind() function
  • no jQuery just plain JavaScript

Setup

1. Add the library to your site's head. Use the minified version for production and the unminified version for development.

<head>
  <!-- all stuff you are using -->
  <script type="text/javascript" src="scripts/scratchcard.min.js"></script>
</head>

2. Initialize the scratch card by using a options object.

var options = {
  id: 'yourCanvasID',
  brushSize: 50,
  lineJoin: 'round',
  percentRequired: 80,
  fillColor: 'rgb(100, 100, 13)'
};
  • id is your canvas ID as a string.

  • brushSize determines how much area the brush should remove as a integer.

  • lineJoin determines how the lines of the revealed area are going to be joined together. Must be one of bevel, round or miter as a string.

  • percentRequired determines how much space should be revealed for the success event to be fired. Should be an integer.

  • fillColor sets the color of the fill that hides the image. This can be all of the CSS color values but has to be put in as a string.

3. Create the new scratch card object and pass the constructor the options object.

var yourScratchCard = new ScratchCard(options);

4. If you want you can add an event listener to the success event.

yourScratchCard.addEventListener('success', function (e) {
  alert('You can do whatever you want here!');
}, false);

5. Profit!

Contributing

If you find any bugs please open up an issue. If you added any features propose a pull request and I will look into it.

License

MIT

scratchcard's People

Contributors

gurumsp avatar

Watchers

James Cloos avatar

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.