html5 canvas鼠标画笔特效

gooood个人博客网站

canvas

html5 canvas鼠标画笔特效
<!DOCTYPE html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Mouse coord (user help)</title> <!-- TODO: Missing CoffeeScript 2 --> <script type="text/javascript"> window.onload=function(){ var canvas = document.getElementById("imgCanvas"); var context = canvas.getContext("2d"); function createImageOnCanvas(imageId) { //canvas.style.display = "block"; //document.getElementById("images").style.overflowY = "hidden"; //var img = new Image(300, 300); //img.src = document.getElementById(imageId).src; //context.drawImage(img, (0), (0)); //onload.... } function draw(e) { var pos = getMousePos(canvas, e); posx = pos.x; posy = pos.y; context.fillStyle = "#000000"; context.fillRect(posx, posy, 4, 4); } window.addEventListener('mousemove', draw, false); function getMousePos(canvas, evt) { var rect = canvas.getBoundingClientRect(); return { x: (evt.clientX - rect.left) / (rect.right - rect.left) * canvas.width, y: (evt.clientY - rect.top) / (rect.bottom - rect.top) * canvas.height }; } } </script> </head> <body> <div></div> <canvas></canvas> <script> // tell the embed parent frame the height of the content if (window.parent && window.parent.parent){ window.parent.parent.postMessage(["resultsFrame", { height: document.body.getBoundingClientRect().height, slug: "4xezb7nL" }], "*") } </script> </body> </html>

本文内容由用户注册发布,仅代表作者或来源网站个人观点,不代表本网站的观点和立场,与本网站无关。本网系信息发布平台,仅提供信息存储空间服务,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本网站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。如因作品内容侵权需删除与其他问题需要同本网联系的,请尽快通过本网的邮箱或电话联系。 
THE END
分享
二维码
< <上一篇
下一篇>>