A simple web-based scratch card simulation inspired by Gpay, where users can scratch off a hidden image using mouse or touch interactions.
- Interactive scratch-off effect.
- Works on both desktop and mobile devices (supports mouse and touch events).
- Reveals a hidden image as the user scratches away the overlay.
- index.html: Contains the basic structure of the webpage and links to the external CSS and JavaScript files.
- style.css: Styles the scratch card container and hidden image.
- script.js: Handles the scratch card functionality, mouse, and touch events.
- The webpage displays a card with a hidden image covered by a scratchable overlay.
- The overlay contains a gradient and text ("Scratch here for #update").
- As users move their mouse or finger over the overlay, the scratched portions of the overlay are removed, revealing the hidden image beneath.
- Clone or download the repository.
- Open the
index.html
file in your web browser. - Scratch the card using your mouse or touch (on mobile devices) to reveal the hidden image.
- Contains the structure of the scratch card, including the hidden image and a
<canvas>
element used for the scratch effect.
- Styles the body and scratch card with a clean, minimalistic design.
- Ensures the canvas covers the hidden image and applies the necessary dimensions and layout.
- Handles the scratch interaction using canvas, mouse, and touch events.
- Creates a gradient overlay and dynamically scratches away areas based on user interaction.
canvas.addEventListener('mousemove', function(e){
if(isDrawing && isMouseDown){
const pos = getMousePos(e);
scratch(pos.x, pos.y);
}
});
function scratch(x, y){
ctx.globalCompositeOperation = 'destination-out';
ctx.beginPath();
ctx.arc(x, y, 50, 0, 2 * Math.PI);
ctx.fill();
}
- Open
index.html
in a browser and scratch the card to see the hidden image.
- HTML5
- CSS3
- JavaScript (Canvas API)
This project is open-source and available under the MIT License.