Have you played scratch card? The kind that can win by accident. Today I will share with you a scratch card effect based on HTML5 technology. Just hold the mouse on the PC, and on the phone, you just need to hold the finger and gently scratch the layer to simulate the real scratch effect.
We use HTML5's canvas Canvas, combined with the API it provides, to draw a gray mask on the Canvas element, and then draw a transparent figure by detecting the user's mouse movement and gestures. This way, you can see the real picture under the Canvas background and achieve the scratch card effect.
HTMLWe only need to add the canvas tag element to the page, and the rest depends on JavaScript. Note that the canvas element is an element that only exists in HTML5 and runs on modern browsers that support HTML5.
Copy the code