{"id":4516,"date":"2024-01-19T17:07:00","date_gmt":"2024-01-19T17:07:00","guid":{"rendered":"https:\/\/codehim.com\/?p=4516"},"modified":"2024-01-22T15:08:16","modified_gmt":"2024-01-22T10:08:16","slug":"create-scratch-card-using-javascript-html5-canvas","status":"publish","type":"post","link":"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/","title":{"rendered":"Create Scratch Card using JavaScript &#038; HTML5 Canvas"},"content":{"rendered":"<p>Yet another code snippet to <strong>create a scratch card using JavaScript<\/strong> and HTML5 canvas. This Vanilla JavaScript plugin allows you to hide your coupon code or other winning code that will show on scratch. You can place any number\/text behind the scratch area. Users can scratch with a cursor or touch swipe. Moreover, it shows a real-time scratching animation.<\/p>\n<h2>How to Create JavaScript Scratch Card<\/h2>\n<p>1. First of all create HTML <code>canvas<\/code> element and other necessary elements like below:<\/p>\n<pre class=\"prettyprint lang-html linenums\">    &lt;div class=\"card\"&gt;\r\n    &lt;div class=\"base\"&gt;Coupon Code: 123456789&lt;\/div&gt;\r\n    &lt;canvas id=\"scratch\" width=\"300\" height=\"60\"&gt;&lt;\/canvas&gt;\r\n    &lt;\/div&gt;<\/pre>\n<p>2. After that, style scratch card with CSS.<\/p>\n<pre class=\"prettyprint lang-css linenums\">    .card{\r\n         width: 300px;\r\n         height: 60px;\r\n         position: relative;\r\n         box-shadow: 1px 2px 6px rgba(0, 0, 0, 0.2);\r\n        }    \r\n        \r\n      .base, #scratch {\r\n        cursor: default;\r\n        height: 60px;\r\n        width: 300px;\r\n          position: absolute;\r\n          top: 0;\r\n          left: 0;\r\n          cursor: grabbing;\r\n      }\r\n      .base {\r\n        line-height: 60px;\r\n        text-align: center;\r\n      }\r\n      #scratch {\r\n        -webkit-tap-highlight-color: rgba(0, 0, 0, 0); \r\n        -webkit-touch-callout: none;\r\n        -webkit-user-select: none;\r\n      }\r\n<\/pre>\n<p>3. Finally, load the scratch card JS file into your HTML document and done.<\/p>\n<pre class=\"prettyprint lang-html linenums\">&lt;!-- scratch-card-with-canvas JS --&gt;\r\n&lt;script src=\"js\/scratch-card.js\"&gt;&lt;\/script&gt;<\/pre>\n<p>That&#8217;s all! hopefully, you have successfully integrated this scratch card animation into your project. If you have any questions or facing any issues, feel free to comment below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yet another code snippet to create a scratch card using JavaScript and HTML5 canvas. This Vanilla JavaScript plugin allows you&#8230;<\/p>\n","protected":false},"author":1,"featured_media":4517,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[56,116],"tags":[94],"class_list":["post-4516","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-others","category-vanilla-javascript","tag-html5-canvas"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Create Scratch Card using JavaScript &amp; HTML5 Canvas &#8212; CodeHim<\/title>\n<meta name=\"description\" content=\"Here is complete code to create scratch card with JavaScript and HTML5 canvas. It is useful for scratch card animation and scratch coupon.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create Scratch Card using JavaScript &amp; HTML5 Canvas &#8212; CodeHim\" \/>\n<meta property=\"og:description\" content=\"Here is complete code to create scratch card with JavaScript and HTML5 canvas. It is useful for scratch card animation and scratch coupon.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/\" \/>\n<meta property=\"og:site_name\" content=\"CodeHim\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codehimofficial\" \/>\n<meta property=\"article:published_time\" content=\"2024-01-19T17:07:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-22T10:08:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codehim.com\/wp-content\/uploads\/2019\/11\/scratch-card-with-canvas-javascript.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1046\" \/>\n\t<meta property=\"og:image:height\" content=\"786\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Asif Mughal\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@CodeHimOfficial\" \/>\n<meta name=\"twitter:site\" content=\"@CodeHimOfficial\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Asif Mughal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/\"},\"author\":{\"name\":\"Asif Mughal\",\"@id\":\"https:\/\/codehim.com\/#\/schema\/person\/cc48f1dbe072a89a62a98171b7db43ed\"},\"headline\":\"Create Scratch Card using JavaScript &#038; HTML5 Canvas\",\"datePublished\":\"2024-01-19T17:07:00+00:00\",\"dateModified\":\"2024-01-22T10:08:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/\"},\"wordCount\":134,\"publisher\":{\"@id\":\"https:\/\/codehim.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/codehim.com\/wp-content\/uploads\/2019\/11\/scratch-card-with-canvas-javascript.png\",\"keywords\":[\"HTML5 Canvas\"],\"articleSection\":[\"Others\",\"Vanilla JavaScript\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/\",\"url\":\"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/\",\"name\":\"Create Scratch Card using JavaScript & HTML5 Canvas &#8212; CodeHim\",\"isPartOf\":{\"@id\":\"https:\/\/codehim.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/codehim.com\/wp-content\/uploads\/2019\/11\/scratch-card-with-canvas-javascript.png\",\"datePublished\":\"2024-01-19T17:07:00+00:00\",\"dateModified\":\"2024-01-22T10:08:16+00:00\",\"description\":\"Here is complete code to create scratch card with JavaScript and HTML5 canvas. It is useful for scratch card animation and scratch coupon.\",\"breadcrumb\":{\"@id\":\"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/#primaryimage\",\"url\":\"https:\/\/codehim.com\/wp-content\/uploads\/2019\/11\/scratch-card-with-canvas-javascript.png\",\"contentUrl\":\"https:\/\/codehim.com\/wp-content\/uploads\/2019\/11\/scratch-card-with-canvas-javascript.png\",\"width\":1046,\"height\":786,\"caption\":\"Create Scratch Card using JavaScript & HTML5 Canvas\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/codehim.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Others\",\"item\":\"https:\/\/codehim.com\/category\/others\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Create Scratch Card using JavaScript &#038; HTML5 Canvas\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/codehim.com\/#website\",\"url\":\"https:\/\/codehim.com\/\",\"name\":\"CodeHim\",\"description\":\"Web Design Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/codehim.com\/#organization\"},\"alternateName\":\"Web Design Codes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/codehim.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/codehim.com\/#organization\",\"name\":\"CodeHim - Web Design Code & Scripts\",\"url\":\"https:\/\/codehim.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/codehim.com\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/codehim.com\/wp-content\/uploads\/2023\/06\/Codehim-short-logo.jpg\",\"contentUrl\":\"http:\/\/codehim.com\/wp-content\/uploads\/2023\/06\/Codehim-short-logo.jpg\",\"width\":280,\"height\":280,\"caption\":\"CodeHim - Web Design Code & Scripts\"},\"image\":{\"@id\":\"https:\/\/codehim.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/codehimofficial\",\"https:\/\/x.com\/CodeHimOfficial\",\"https:\/\/www.instagram.com\/codehim\/\",\"https:\/\/www.linkedin.com\/company\/codehim\",\"https:\/\/co.pinterest.com\/codehim\/\",\"https:\/\/www.youtube.com\/@codehim\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/codehim.com\/#\/schema\/person\/cc48f1dbe072a89a62a98171b7db43ed\",\"name\":\"Asif Mughal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/codehim.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b25bfcd7d4e341c2c6f785a88d8ad2a4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b25bfcd7d4e341c2c6f785a88d8ad2a4?s=96&d=mm&r=g\",\"caption\":\"Asif Mughal\"},\"description\":\"I code and create web elements for amazing people around the world. I like work with new people. New people new Experiences. I truly enjoy what I'm doing, which makes me more passionate about web development and coding. I am always ready to do challenging tasks whether it is about creating a custom CMS from scratch or customizing an existing system.\",\"sameAs\":[\"https:\/\/codehim.com\"],\"url\":\"https:\/\/codehim.com\/author\/asif-mughal\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Create Scratch Card using JavaScript & HTML5 Canvas &#8212; CodeHim","description":"Here is complete code to create scratch card with JavaScript and HTML5 canvas. It is useful for scratch card animation and scratch coupon.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/","og_locale":"en_US","og_type":"article","og_title":"Create Scratch Card using JavaScript & HTML5 Canvas &#8212; CodeHim","og_description":"Here is complete code to create scratch card with JavaScript and HTML5 canvas. It is useful for scratch card animation and scratch coupon.","og_url":"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/","og_site_name":"CodeHim","article_publisher":"https:\/\/www.facebook.com\/codehimofficial","article_published_time":"2024-01-19T17:07:00+00:00","article_modified_time":"2024-01-22T10:08:16+00:00","og_image":[{"width":1046,"height":786,"url":"https:\/\/codehim.com\/wp-content\/uploads\/2019\/11\/scratch-card-with-canvas-javascript.png","type":"image\/png"}],"author":"Asif Mughal","twitter_card":"summary_large_image","twitter_creator":"@CodeHimOfficial","twitter_site":"@CodeHimOfficial","twitter_misc":{"Written by":"Asif Mughal","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/#article","isPartOf":{"@id":"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/"},"author":{"name":"Asif Mughal","@id":"https:\/\/codehim.com\/#\/schema\/person\/cc48f1dbe072a89a62a98171b7db43ed"},"headline":"Create Scratch Card using JavaScript &#038; HTML5 Canvas","datePublished":"2024-01-19T17:07:00+00:00","dateModified":"2024-01-22T10:08:16+00:00","mainEntityOfPage":{"@id":"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/"},"wordCount":134,"publisher":{"@id":"https:\/\/codehim.com\/#organization"},"image":{"@id":"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/#primaryimage"},"thumbnailUrl":"https:\/\/codehim.com\/wp-content\/uploads\/2019\/11\/scratch-card-with-canvas-javascript.png","keywords":["HTML5 Canvas"],"articleSection":["Others","Vanilla JavaScript"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/","url":"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/","name":"Create Scratch Card using JavaScript & HTML5 Canvas &#8212; CodeHim","isPartOf":{"@id":"https:\/\/codehim.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/#primaryimage"},"image":{"@id":"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/#primaryimage"},"thumbnailUrl":"https:\/\/codehim.com\/wp-content\/uploads\/2019\/11\/scratch-card-with-canvas-javascript.png","datePublished":"2024-01-19T17:07:00+00:00","dateModified":"2024-01-22T10:08:16+00:00","description":"Here is complete code to create scratch card with JavaScript and HTML5 canvas. It is useful for scratch card animation and scratch coupon.","breadcrumb":{"@id":"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/#primaryimage","url":"https:\/\/codehim.com\/wp-content\/uploads\/2019\/11\/scratch-card-with-canvas-javascript.png","contentUrl":"https:\/\/codehim.com\/wp-content\/uploads\/2019\/11\/scratch-card-with-canvas-javascript.png","width":1046,"height":786,"caption":"Create Scratch Card using JavaScript & HTML5 Canvas"},{"@type":"BreadcrumbList","@id":"https:\/\/codehim.com\/others\/create-scratch-card-using-javascript-html5-canvas\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codehim.com\/"},{"@type":"ListItem","position":2,"name":"Others","item":"https:\/\/codehim.com\/category\/others\/"},{"@type":"ListItem","position":3,"name":"Create Scratch Card using JavaScript &#038; HTML5 Canvas"}]},{"@type":"WebSite","@id":"https:\/\/codehim.com\/#website","url":"https:\/\/codehim.com\/","name":"CodeHim","description":"Web Design Code Snippets","publisher":{"@id":"https:\/\/codehim.com\/#organization"},"alternateName":"Web Design Codes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codehim.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/codehim.com\/#organization","name":"CodeHim - Web Design Code & Scripts","url":"https:\/\/codehim.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codehim.com\/#\/schema\/logo\/image\/","url":"http:\/\/codehim.com\/wp-content\/uploads\/2023\/06\/Codehim-short-logo.jpg","contentUrl":"http:\/\/codehim.com\/wp-content\/uploads\/2023\/06\/Codehim-short-logo.jpg","width":280,"height":280,"caption":"CodeHim - Web Design Code & Scripts"},"image":{"@id":"https:\/\/codehim.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codehimofficial","https:\/\/x.com\/CodeHimOfficial","https:\/\/www.instagram.com\/codehim\/","https:\/\/www.linkedin.com\/company\/codehim","https:\/\/co.pinterest.com\/codehim\/","https:\/\/www.youtube.com\/@codehim"]},{"@type":"Person","@id":"https:\/\/codehim.com\/#\/schema\/person\/cc48f1dbe072a89a62a98171b7db43ed","name":"Asif Mughal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codehim.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b25bfcd7d4e341c2c6f785a88d8ad2a4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b25bfcd7d4e341c2c6f785a88d8ad2a4?s=96&d=mm&r=g","caption":"Asif Mughal"},"description":"I code and create web elements for amazing people around the world. I like work with new people. New people new Experiences. I truly enjoy what I'm doing, which makes me more passionate about web development and coding. I am always ready to do challenging tasks whether it is about creating a custom CMS from scratch or customizing an existing system.","sameAs":["https:\/\/codehim.com"],"url":"https:\/\/codehim.com\/author\/asif-mughal\/"}]}},"views":19392,"_links":{"self":[{"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/posts\/4516","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/comments?post=4516"}],"version-history":[{"count":0,"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/posts\/4516\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/media\/4517"}],"wp:attachment":[{"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/media?parent=4516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/categories?post=4516"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codehim.com\/wp-json\/wp\/v2\/tags?post=4516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}