前端签名插件 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>
相关推荐
search71 小时前
前端设计:CRG 3--CDC error
前端
治金的blog1 小时前
vben-admin和vite,ant-design-vue的结合的联系
前端·vscode
利刃大大2 小时前
【Vue】Vue2 和 Vue3 的区别
前端·javascript·vue.js
荔枝一杯酸牛奶3 小时前
HTML 表单与表格布局实战:两个经典作业案例详解
前端·html
Charlie_lll4 小时前
学习Three.js–纹理贴图(Texture)
前端·three.js
yuguo.im4 小时前
我开源了一个 GrapesJS 插件
前端·javascript·开源·grapesjs
安且惜4 小时前
带弹窗的页面--以表格形式展示
前端·javascript·vue.js
GISer_Jing5 小时前
AI驱动营销:业务技术栈实战(From AIGC,待总结)
前端·人工智能·aigc·reactjs
GIS之路7 小时前
GDAL 实现影像裁剪
前端·python·arcgis·信息可视化
AGMTI7 小时前
webSock动态注册消息回调函数功能实现
开发语言·前端·javascript