当前位置: 首页 > news >正文

网站建设优化今天国际新闻最新消息10条

网站建设优化,今天国际新闻最新消息10条,湘潭天元建设集团有限公司董事长,出站链接对网站有什么影响实现效果: 要使用Canvas实现移动端网页电子签名,可以按照以下步骤: 在HTML文件中创建一个Canvas元素,并设置其宽度和高度,以适配移动设备的屏幕大小。 // 创建一个canvas元素 let canvas document.createElement(&q…

实现效果:



要使用Canvas实现移动端网页电子签名,可以按照以下步骤:

在HTML文件中创建一个Canvas元素,并设置其宽度和高度,以适配移动设备的屏幕大小。

// 创建一个canvas元素
let canvas = document.createElement("canvas");
// 设置canvas元素的宽度和高度
canvas.width = 300;
canvas.height = 200;

在JavaScript文件中获取Canvas元素,并获取其上下文对象。

let ctx = canvas.getContext('2d');

设置绘制路径的样式,包括颜色、宽度等。

ctx.strokeStyle = '#000000'; // 设置绘制线条的颜色为黑色
ctx.lineWidth = 2; // 设置绘制线条的宽度为2像素

监听移动设备的触摸事件,在触摸事件的回调函数中获取触摸点的坐标,并使用Canvas绘制路径。

var isDrawing = false; // 是否正在绘制路径canvas.addEventListener('touchstart', function(e) {isDrawing = true;var touch = e.touches[0];var x = touch.pageX - canvas.offsetLeft;var y = touch.pageY - canvas.offsetTop;ctx.beginPath(); // 开始绘制路径ctx.moveTo(x, y); // 移动到起始点
});canvas.addEventListener('touchmove', function(e) {if (isDrawing) {var touch = e.touches[0];var x = touch.pageX - canvas.offsetLeft;var y = touch.pageY - canvas.offsetTop;ctx.lineTo(x, y); // 绘制直线到当前点ctx.stroke(); // 绘制路径}
});canvas.addEventListener('touchend', function(e) {isDrawing = false;
});

可以添加其他功能,如清除画布、保存签名等。

const startDrawing = (e) => {isDrawing = true;const { clientX, clientY } = e.touches ? e.touches[0] : e;const x = clientX - canvas.offsetLeft;const y = clientY - canvas.offsetTop;ctx.beginPath(); // 开始绘制路径ctx.moveTo(x, y); // 移动到起始点
};const draw = (e) => {if (isDrawing) {const { clientX, clientY } = e.touches ? e.touches[0] : e;const x = clientX - canvas.offsetLeft;const y = clientY - canvas.offsetTop;ctx.lineTo(x, y); // 绘制直线到当前点ctx.stroke(); // 绘制路径}
};const stopDrawing = () => {isDrawing = false;
};// 添加触摸事件
canvas.addEventListener("touchstart", startDrawing);
canvas.addEventListener("touchmove", draw);
canvas.addEventListener("touchend", stopDrawing);// 添加鼠标事件
canvas.addEventListener("mousedown", startDrawing);
canvas.addEventListener("mousemove", draw);
canvas.addEventListener("mouseup", stopDrawing);

以上就是使用Canvas实现移动端网页电子签名的基本步骤。你可以根据自己的需求进行进一步的扩展和优化。



下面给出完整代码:

<!DOCTYPE html>
<html><head><title>Canvas头像</title></head><body><button onclick="saveSignature()">保存</button><button onclick="clearCanvas()">清除</button><script>let canvas = null;let ctx = null;let isDrawing = false; // 是否正在绘制路径(function initCanvas() {// 创建一个canvas元素canvas = document.createElement("canvas");// 设置canvas元素的宽度和高度canvas.width = 300;canvas.height = 200;// 将canvas元素添加到body元素中document.body.appendChild(canvas);// 获取canvas元素的上下文对象ctx = canvas.getContext("2d");ctx.strokeStyle = "#000000"; // 设置绘制线条的颜色为黑色ctx.lineWidth = 2; // 设置绘制线条的宽度为2像素const startDrawing = (e) => {isDrawing = true;const { clientX, clientY } = e.touches ? e.touches[0] : e;const x = clientX - canvas.offsetLeft;const y = clientY - canvas.offsetTop;ctx.beginPath(); // 开始绘制路径ctx.moveTo(x, y); // 移动到起始点};const draw = (e) => {if (isDrawing) {const { clientX, clientY } = e.touches ? e.touches[0] : e;const x = clientX - canvas.offsetLeft;const y = clientY - canvas.offsetTop;ctx.lineTo(x, y); // 绘制直线到当前点ctx.stroke(); // 绘制路径}};const stopDrawing = () => {isDrawing = false;};// 添加触摸事件canvas.addEventListener("touchstart", startDrawing);canvas.addEventListener("touchmove", draw);canvas.addEventListener("touchend", stopDrawing);// 添加鼠标事件canvas.addEventListener("mousedown", startDrawing);canvas.addEventListener("mousemove", draw);canvas.addEventListener("mouseup", stopDrawing);})();// 清除画布function clearCanvas() {ctx.clearRect(0, 0, canvas.width, canvas.height);}// 保存签名为图片function saveSignature() {const imageData = canvas.toDataURL(); // 将Canvas内容转换为图片数据const link = document.createElement("a");link.href = imageData;link.download = "signature.png"; // 设置下载图片的文件名link.click(); // 模拟点击下载链接}</script></body>
</html>

http://www.tj-hxxt.cn/news/112727.html

相关文章:

  • 番禺制作网站系统软文广告发稿
  • 做外贸常用那几个网站最好的小说网站排名
  • 大亚湾住房规划建设局网站广东优化疫情防控措施
  • 昆山 网站建设网络营销的市场背景
  • 网站策划与制作互联网营销师报名入口官网
  • 汕头 网站腾讯广告代理商加盟
  • 做网站的首页下拉列表电商引流推广方法
  • 设计建筑江北seo页面优化公司
  • 淘宝客网站免费建站百度竞价广告投放
  • 成都网站建设公司有哪些软文素材网
  • 深圳营销型网站建设唐山seo推广公司
  • wordpress默认后台登陆关键词优化app
  • 网站建设蘑菇街刷关键词怎么刷
  • wordpress 周报排名优化外包公司
  • 做视频网站视频短片湖南网站网络推广哪家奿
  • 做外贸服饰哪个个网站好免费b2b推广网站
  • 招聘网站分析报告怎么做站长统计工具
  • 北京手机网站设计友情链接系统
  • 来广营做网站公司seo上海推广公司
  • 济南网站怎么做seo天堂tv在线观看
  • 网站运营需要++做哪些工作优化推广关键词
  • 东营市住房和建设委员会网站网站建设公司地址在哪
  • 如何做淘宝的站外网站推广网络营销和市场营销的区别
  • 深圳营销型网站建设服务win7优化工具
  • 临朐做网站简述网站建设的一般流程
  • 哈尔滨网站建设设计网站一年了百度不收录
  • 做兼职的网站都有哪些北京培训seo哪个好
  • 邯郸微信公众号开发哈尔滨网络seo公司
  • 网站论坛模板百度推广开户代理
  • 建筑工程网格化监管来宾seo