前端签名插件 smooth-signature

html 复制代码
<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>签名</title>
		<style>
			.container {
				display: flex;
			}

			.handler {
				display: grid;
			}
		</style>
	</head>
	<body>
		<div class="container">
			<canvas id="sign-board" style="border: 3px dotted #a7a7a7; border-radius: 8px;"></canvas>
			<div class="handler">
				<button onclick="back()">退一步</button>
				<button onclick="clearing()">清屏</button>
				<button onclick="getPNGimg()">确定</button>
			</div>
		</div>



		<script src="https://unpkg.com/smooth-signature/dist/index.umd.min.js"></script>
		<script>
			const canvas = document.querySelector("#sign-board");
			const signature = new SmoothSignature(canvas, {
				width: 1000,
				height: 600,
				scale: 2,
				minWidth: 4,
				maxWidth: 10,
				bgColor: '#efefef'
			});



			// 生成PNG
			function getPNGimg() {
				const img = signature.getPNG() // 或者 signature.toDataURL()
				console.log(img);
			}

			// 清屏
			function clearing() {
				signature.clear()
			}


			// 撤销
			function back() {
				signature.undo()
			}


			// 是否为空
			function isNull() {
				const isNull = signature.isEmpty();
				console.log(isNull);
			}


			function rotate90() {
				signature.getRotateCanvas(90)
			}
		</script>
	</body>
</html>
相关推荐
步行cgn13 小时前
为什么既要 web.xml 又要 springmvc.xml?能不能只配一个?
xml·前端·hive
风骏时光牛马13 小时前
大模型综合能力评测:多维度性能与对齐效果对比
前端
winfredzhang13 小时前
从零手写一个毛玻璃风格的页面搭建台:单文件 HTML 实现组件放置、面板磁吸与图层管理
前端·html
葡萄城技术团队21 小时前
1000 人协同压测的环境瓶颈排查:CPU 争用与 Wi\-Fi
前端
excel1 天前
Marked 与 Markdown 有什么区别?该怎么选?
前端
Da Da 泓1 天前
五子棋 Web 端测试用例报告
前端·网络·websocket·网络协议·测试用例·项目
zxcvb1531 天前
远程查看本地文档:一条轻量 Web 文件服务的工程化链路
前端·远程查看文档
niucloud-admin1 天前
NIUCLOUD PHP SAAS上门家政使用文档:城市管理
java·前端·php
北岛贰1 天前
啵啵音乐迎来全新升级!
前端
hkNaruto1 天前
【AI】基于大模型的AI游戏地图生成、控制方案:AI Native Game Harness 迁移操作手册
前端·人工智能·游戏