3

Is it possible with javascript?

I'm trying to implement a scratchcard type thing, and I was wondering if the user could 'scratch it' with his cursor and then javascript would remove/erase the image to show the text below.

But i've not been able to find anything (javascript wise) which can erase abit (cursor location) of an image.

Does anyone have any suggestions/ideas?

Thanks.

James Andrew
  • 7,197
  • 14
  • 46
  • 62

2 Answers2

6

Use html5 canvas element.

Checkout this fiddle for an example: http://jsfiddle.net/ArtBIT/WUXDb/1/

ArtBIT
  • 3,931
  • 28
  • 39
  • Is it possible to do this for mobile users too, using `touchmove`? – Justin Jul 29 '14 at 20:57
  • @Justin yes it is, you just need to rename the `onmousedown`, `onmouseup` and `onmousemove` events to the corresponding touch event handlers, and change the `onmousemove` method a bit, since the touch coordinates are handled a bit differently (http://www.w3.org/TR/touch-events/#the-touchmove-event) – ArtBIT Jul 30 '14 at 09:42