Giter Site home page Giter Site logo

pinguo-liangyunzhu / jquery.eraser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from boblemarin/jquery.eraser

0.0 2.0 0.0 478 KB

jQuery plugin that makes an image erasable (with mouse or touch movements)

Home Page: http://minimal.be/lab/jQuery.eraser/

HTML 33.93% JavaScript 66.07%

jquery.eraser's Introduction

#jQuery.eraser v0.5.2

a jQuery plugin that makes an image erasable (with mouse or touch movements)

This plugin replaces the targeted image by an interactive canvas that can be erased using touch or mouse inputs. You can specify a callback for completion and set the brush size.

Please note that I don't claim that the completion detection process is ultimately accurate. In fact you should rather use a completeRatio around 0.8 if you want a near-complete erase process.

#What's new in 0.5.2

Added the 'enable/disable/enabled' methods (see details in the Usage section)

#What's new in 0.5.1

Added a 'progress' method (see details in the Usage section)

###What was new in 0.5.0

Eraser now takes care of checking if the target image is already loaded. If not, it registers a callback on the load event and waits for the bitmap data to be available.

You don't have to worry anymore about anything but erasing.

#Usage :

To transform an image or canvas into an erasable canvas, just use this syntax :

$('#yourImage').eraser();

To specify a brush size, add some options (default value is 40) :

$('#yourImage').eraser( { size: 30 } );
// and you can also change the size later :
// $('#yourImage').eraser( 'size', 30 } );

You can reset the canvas (back to the original image) with this code :

$('#yourImage').eraser('reset');

And you can erase all the canvas' content by calling :

$('#yourImage').eraser('clear');

You can change whether erasing is enabled or disabled by calling the enable or disable methods :

$('#yourImage').eraser('enable');
$('#yourImage').eraser('disable');

And you can check whether erasing is enabled or disabled by calling :

$('#yourImage').eraser('enabled');

To get a callback when 50% of the image has been erased, use the following options :

$('#yourImage').eraser( {
	completeRatio: .5,
	completeFunction: showResetButton
});

If you need to manually query the progress of the user, use the progress method :

var progress = $('#yourImage').eraser('progress'); // returns a value between 0 and 1

There is also a progressFunction option where you can provide a function that will be called each time the user erases a new area. It receives as argument the normalized progress value (0.0 to 1.0).

$('#yourImage').eraser( {
	progressFunction: function(p) {
		console.log(Math.round(p * 100) + '%');
	}
});

#URLs :

* https://github.com/boblemarin/jQuery.eraser
* http://minimal.be/lab/jQuery.eraser/

Created by @boblemarin

jquery.eraser's People

Contributors

boblemarin avatar fantix avatar gerrit avatar jackwakefield avatar liubiantao avatar

Watchers

 avatar  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.