当前位置:网站首页>H5 < canvas > label + native JS self-made a simple drawing tool
H5 < canvas > label + native JS self-made a simple drawing tool
2022-04-22 12:27:00 【Yunmo - brother Kuang's blog】
canvas Label Introduction : Novice tutorial https://www.runoob.com/html/html5-canvas.html
<!-- * @Author: bkk * @weixin: biankuan1996 * @email: [email protected] * @Date: 2021-06-03 21:25:13 * @LastEditTime: 2021-06-03 22:30:59 -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> canvas </title>
<style> canvas {
display: block; border: 1px solid #333; } div{
padding: 20px 0; display: flex; justify-content: space-between; } div {
width: 500px; } </style>
</head>
<body>
<canvas id="myCanvas" width=500 height=500></canvas>
<div>
<span> Brush color :<input type="color" id="colorBtn"></span>
<button class="clear"> Clear the canvas </button>
</div>
<script> // @type {HTMLCanvasElement} // Get canvas object var myCanvas = document.querySelector("#myCanvas"), clearBtn = document.getElementsByClassName("clear")[0] // Get canvas environment var ctx = myCanvas.getContext("2d"); var flag = false;// Define a boolean variable to judge the state of the mouse // When the mouse is pressed on the canvas myCanvas.onmousedown = function (e) {
// Began to draw ctx.beginPath(); // Define the coordinates when the mouse is pressed as the start coordinates ctx.moveTo(e.clientX, e.clientY); // modify flag The value of is true flag = !flag; } // When the color selection box changes , Copy the color selected by the user to the brush color colorBtn.onchange = function () {
ctx.strokeStyle = this.value; } // When the mouse slides over the canvas myCanvas.onmousemove = function (e) {
// If flag == true That is, when the mouse is pressed, perform the following operations if (flag) {
ctx.lineTo(e.clientX, e.clientY) ctx.stroke(); } } // When the mouse is released myCanvas.onmouseup = function (e) {
// When the mouse is released ,flag Restore to the initial value flag = !flag; } // Clear the canvas clearBtn.onclick = function () {
// Define that the eraser is the same width and height as the canvas ctx.clearRect(0, 0, 500, 500) } </script>
</body>
</html>
版权声明
本文为[Yunmo - brother Kuang's blog]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221225118146.html
边栏推荐
- Build: makefile
- 购物表格制作
- Ont and ONU
- 【深入理解TcaplusDB技术】读取列表指定位置数据接口说明——[List表]
- JS基础14
- What is the lifecycle of automated testing?
- In recent years, oppo, Xiaomi and other mobile phone manufacturers have begun to take the road of self-developed chips. Can this road run through?
- [in depth understanding of tcallusdb technology] scan data interface description - [list table]
- ROS2学习笔记(十)从turtlesim学习ROS2的工作空间
- 腾讯云域名绑定
猜你喜欢

JS基础13

Meaning of C language% 7.2d, --7d,% 7.2f,% 0.2f
![【深入理解TcaplusDB技术】读取列表指定位置数据接口说明——[List表]](/img/ed/cccd5dee09d2f0a3e6c788bd265b36.png)
【深入理解TcaplusDB技术】读取列表指定位置数据接口说明——[List表]

LeetCode 83、删除排序链表中的重复元素
![[concurrent programming 050] type and description of memory barrier?](/img/2b/9035c20c45f3f33c97639341315f72.png)
[concurrent programming 050] type and description of memory barrier?
![[concurrent programming 052] talk about double check lock and its advantages?](/img/45/0d35b6b358f6605c46300f749dcd3d.png)
[concurrent programming 052] talk about double check lock and its advantages?
![[in depth understanding of tcallusdb technology] description of data interface for batch deletion of specified location in list - [list table]](/img/ed/cccd5dee09d2f0a3e6c788bd265b36.png)
[in depth understanding of tcallusdb technology] description of data interface for batch deletion of specified location in list - [list table]

ROS2学习笔记(九)从turtlesim学习ROS2的bag录制
![【深入理解TcaplusDB技术】删除列表所有数据接口说明——[List表]](/img/ed/cccd5dee09d2f0a3e6c788bd265b36.png)
【深入理解TcaplusDB技术】删除列表所有数据接口说明——[List表]

JS基础8
随机推荐
订货系统打破批发企业瓶颈期,助力企业数字化转型
[deeply understand tcallusdb technology] insert data into the specified location of the list interface description - [list table]
[concurrent programming 052] talk about double check lock and its advantages?
.NET宝藏API之:OutputFormatter,格式化输出对象
【深入理解TcaplusDB技术】扫描数据接口说明——[List表]
机器学习 训练模板,汇总多个分类器
[logical fallacies in life] controlling violence with violence and suppressing rationality
栈的概念和操作
[concurrent programming 047] cache locking performance is better than bus locking. Why not eliminate bus locking?
NER简单综述
射频芯片在手机上起到什么作用?
JS基础9
带你详细入门华为云会议【玩转华为云】
Pytorch processes RNN input variable length sequence padding
Free trial for the first three months! Borui data alarm platform onealert is in progress
CPU和GPU有什么区别?
Synchronized lock and its expansion
购买不同品牌的手机,怎么对比硬件配置?
Redis新版本发布,你还认为Redis是单线程?
Codeforces Round #783 (Div. 2)