前端签名插件 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>
相关推荐
万物得其道者成8 小时前
前端大整数精度丢失:一次踩坑后的实战解决方案(`json-bigint`)
前端·json
鹏北海9 小时前
移动端 H5 响应式字体适配方案完全指南
前端
柳杉10 小时前
使用AI从零打造炫酷医疗数据可视化大屏,源码免费拿!
前端·javascript·数据可视化
凌云拓界10 小时前
前端开发的“平衡木”:在取舍之间找到最优解
前端·性能优化·架构·前端框架·代码规范·设计规范
zhengfei61111 小时前
【XSS payload 】一个经典的XSS payload
前端·xss
全栈老石12 小时前
手写一个无限画布 #1:坐标系的谎言
前端·canvas
XW010599912 小时前
4-11判断素数
前端·python·算法·素数
J2虾虾12 小时前
Spring Boot中使用@Scheduled做定时任务
java·前端·spring boot
Heo12 小时前
深入React19任务调度器Scheduler
前端·javascript·面试
一枚前端小姐姐13 小时前
Vue3 + Pinia 状态管理,从入门到模块化
前端·vue.js