Today I will teach you how to make a small program, using CSS3, H5 and JS to make a fun simple drawing board. Friends who are interested can try it. The code is posted below. Everyone can also use their creativity to change some functions.
html: <body> <canvas width="800" height="600" id="c1"> <span> </span> </canvas> <ul id="ul1"> <li>颜色版:<input id="color" type="color"/></li> <li>笔触:<input id="num" type="number" min="0" max="100"/></li> <li></li> </ul> </body> css: <style> *{ margin:0; padding:0;} body{ background:#000;} canvas{ background:#fff; float:left;} span{ color:#fff; font-size:80px;} #ul1{width:100px;height:600px; float:left; background:#ccc;} </style> javascript: <script> window.onload=function(){ var oC=document.getElementById('c1'); var oColor=document.getElementById('color'); var oNum=document.getElementById('num'); var gd=oC.getContext('2d');//画笔 oNum.onchange=function(){ gd.lineWidth = oNum.value; strokeFn(); }; oColor.onchange=function(){ gd.strokeStyle = oColor.value; strokeFn(); }; strokeFn(); function strokeFn(){ gd.beginPath(); oC.onmousedown=function(ev){ gd.moveTo(ev.clientX,ev.clientY); oC.onmousemove=function(ev){ gd.lineTo(ev.clientX,ev.clientY); gd.stroke(); }; oC.onmouseup=function(){ oC.onmousemove=oC.onmouseup=null; }; return false; }; } }; </script>
I believe you have mastered the methods after reading these cases. For more exciting information, please pay attention to other related articles on the php Chinese website!
Related reading:
How to change the mouseover style without using CSS
How to use CSS to create an image rotation effect
How to optimize HTML web pages
The above is the detailed content of Make a simple sketchpad code using JS and html. For more information, please follow other related articles on the PHP Chinese website!

A consistent HTML encoding style is important because it improves the readability, maintainability and efficiency of the code. 1) Use lowercase tags and attributes, 2) Keep consistent indentation, 3) Select and stick to single or double quotes, 4) Avoid mixing different styles in projects, 5) Use automation tools such as Prettier or ESLint to ensure consistency in styles.

Solution to implement multi-project carousel in Bootstrap4 Implementing multi-project carousel in Bootstrap4 is not an easy task. Although Bootstrap...

How to achieve the effect of mouse scrolling event penetration? When we browse the web, we often encounter some special interaction designs. For example, on deepseek official website, �...

The default playback control style of HTML video cannot be modified directly through CSS. 1. Create custom controls using JavaScript. 2. Beautify these controls through CSS. 3. Consider compatibility, user experience and performance, using libraries such as Video.js or Plyr can simplify the process.

Potential problems with using native select on mobile phones When developing mobile applications, we often encounter the need for selecting boxes. Normally, developers...

What are the disadvantages of using native select on your phone? When developing applications on mobile devices, it is very important to choose the right UI components. Many developers...

Use Three.js and Octree to optimize collision handling of third-person roaming in the room. Use Octree in Three.js to implement third-person roaming in the room and add collisions...

Issues with native select on mobile phones When developing applications on mobile devices, we often encounter scenarios where users need to make choices. Although native sel...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
