时间:2021-05-28
本文实例为大家分享了html5 canvas在图片上画超链接的具体代码,供大家参考,具体内容如下
1. html
<canvas id="canvasFile" style="margin-top:15px;" width="500" height="400"></canvas> <input type="button" id="btnRedo" value="Re-Draw" class="btn btn-warning"/>2. javascript
var photoW = 400; var photoH = 300; var photo; // logic load image into canvas // ... // e.g. // photo = new Image(); // photo.onload = function() { // draw photo into canvas when ready // ctx.drawImage(photo, 0, 0, photoW, photoH); // }; // load photo into canvas // photo.src = picURL; // canvas highlight var canvas = document.getElementById('canvasFile'), ctx = canvas.getContext('2d'), img = new Image; var btnDone = document.getElementById('btnDone'); var btnRedo = document.getElementById('btnRedo'); ctx.strokeStyle = '#FF0000'; function DrawDot(x, y) { var centerX = x; var centerY = y; var radius = 2; ctx.beginPath(); ctx.arc(centerX, centerY, radius, 0, 2 * Math.PI, false); ctx.fillStyle = 'red'; ctx.fill(); ctx.lineWidth = 2; ctx.strokeStyle = '#FF0000'; ctx.stroke(); } function startDrawing() { ctx.drawImage(img, 0, 0, photoW, photoH); canvas.onmousemove = mousemoving; canvas.onmousedown = mousedownhandle; canvas.onmouseup = mouseuphandle; // ## mobile events //touchstart – to toggle drawing mode “on” //touchend – to toggle drawing mode “off” //touchmove – to track finger position, used in drawing canvas.addEventListener('touchmove', touchmove, false); canvas.addEventListener('touchend', mouseuphandle, false); btnRedo.onclick = function (e) { ctx.clearRect(0, 0, ctx.width, ctx.height); ctx.drawImage(photo, 0, 0, photoW, photoH); savedrawing(); } } function savedrawing(e) { var image = document.getElementById('canvasFile').toDataURL("image/jpeg"); image = image.replace('data:image/jpeg;base64,', ''); $("#imgNric1").val(image); }; function mousemoving(e) { if (drawing) { mousedownhandle(e); } } var drawing = false; function mousedownhandle(e) { drawing = true; var r = canvas.getBoundingClientRect(), x = e.clientX - r.left, y = e.clientY - r.top; DrawDot(x, y); } function mouseuphandle(e) { savedrawing(); e.preventDefault(); drawing = false; } //// mobile touch events function touchmove(e) { if (e.clientX > 800) { mousedownhandle(e); return; } var r = canvas.getBoundingClientRect(), //event.changedTouches[0].pageX + ":" + event.changedTouches[0].pageY; x = e.changedTouches[0].pageX - r.left, y = e.changedTouches[0].pageY - r.top; DrawDot(x, y); e.preventDefault(); }以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
示例使用HTML5的canvas标签和Javascript脚本,简单的编写了装载图片效果,请使用支持HTML5的浏览器预览效果:下图为以逐渐横向栅格的效果图ht
使用HTML5制作时钟复制代码代码如下:html5时钟varClock=function(canvas,options){this.canvas=canvas;
Canvas是HTML5新增的组件,它就像一块幕布,可以用JavaScript在上面绘制各种图表、动画等。没有Canvas的年代,绘图只能借助Flash插件实现
本文实例讲述了javascript+HTML5的canvas实现七夕情人节3D玫瑰花效果。分享给大家供大家参考。具体如下:下面的玫瑰绘制用到了HTML5的can
通过javascript把图片转化为字符画1.获取上传图片对象数据Javascript无法直接获取本地上传的图片的数据,html5可以解决这一问题。html5里