jQuery Plugin to Enable Drawing on HTML5 Canvas – jQuery sketchIt

jQuery Drawing on HTML5 Canvas
Code Snippet:sketchIt
Author: Gareth Cadwaladr
Published: March 1, 2024
Last Updated: March 4, 2024
Downloads: 3,249
License: MIT
Edit Code online: View on CodePen
Read More

A simple, easy-to-use jQuery & HTML5 Canvas-based plugin that enables simple drawing functionality on an automatically generated html5 canvas.

How to Use SketchIt for Drawing HTML5 Canvas:

1. First of all, load the jQuery, jQuery Mobile & UI, and sketchIt into an HTML document.

<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>

<!-- jQuery Mobile -->
<script src="https://code.jquery.com/mobile/1.5.0-rc1/jquery.mobile-1.5.0-rc1.min.js"></script>

<!-- jQuery UI -->
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>

2. Also, include the sketchIt javascript and CSS files on your page.

<!-- sketchIt Js -->
<script src="src/jquery.sketchIt.min.js"></script>

<!-- sketchIt CSS -->
<link rel="stylesheet" type="text/css" href="index-src/main.css">

3. Create a container, a div element with the unique id in which you want to load sketchIt drawing board.

<div id="drawing"></div>

4. Initialize the plugin in the jQuery document ready function with the div id selector.

$(document).ready(function(){

$('#drawing').sketchIt();

});

5. To enable drawing tools, put the following option true. Default: false, type: bool

$('#drawing').sketchIt({
   tools:true,
});

6. To change the color on plugin initialization. Default: black, type: string

$('#drawing').sketchIt({
   color: 'green'
});

7. To style the drawing board, the basic CSS is as follows.

#drawing {
    height: 200px;
}
#tools {
    position: fixed;
    z-index: 1000;
    top: 60px;
    right: 60px;
}
#tools {
    background-color: #ddd;
    color: #565656;
    width: 62px;
    font-family: Arial, Sans-serif;
    font-size: 0.85em;
}
#tools i {
    padding: 3px;
    display: block;
}
#tools * {
    margin:0px;
    padding:0px;
}
#tools ul {
    clear: both;
}
#tools li {
    list-style-type:none;
    min-width: 50px;
    min-height: 50px;
    padding: 5px;
    position: relative;
    background-color: #ddd;
    text-align:center;
}
#tools span {
    display: block;
    border: 1px solid #bbb;
    width: 50px;
    height: 50px;
    background-color: #ddd;
}
span.text {
    font-size: 3.3em;
}
#tools li ul {
    display:none;
    position: relative;
    left: -60px;
    top: 0px;
    z-index: 1000;
}
#tools li:hover {
    background-color: #bbb;
}
#tools li:hover span {
    border-color: #999;
}
#tools li:hover>ul {
    display:block !important;
    position: absolute;
}
#tools .current {
    background-color: #bbb;
}
.catview {
    border: 0px !important;
}

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About CodeHim

Free Web Design Code & Scripts - CodeHim is one of the BEST developer websites that provide web designers and developers with a simple way to preview and download a variety of free code & scripts. All codes published on CodeHim are open source, distributed under OSD-compliant license which grants all the rights to use, study, change and share the software in modified and unmodified form. Before publishing, we test and review each code snippet to avoid errors, but we cannot warrant the full correctness of all content. All trademarks, trade names, logos, and icons are the property of their respective owners... find out more...

Please Rel0ad/PressF5 this page if you can't click the download/preview link

X