首页 > Web开发 > 详细

html5 canvas 鼠标绘制

时间:2015-02-10 23:06:51      阅读:363      评论:0      收藏:0      [点我收藏+]
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
body{
    background:pink;
    }
#c1{
    background:white;
    }    


</style>

<script>
window.onload = function ()
{
    var oC = document.getElementById(‘c1‘);
    
    var oGC = oC.getContext(‘2d‘);
    
    oC.onmousedown = function (ev)
    {
        var ev = ev || event;
        oGC.moveTo(ev.clientX - oC.offsetLeft, ev.clientY - oC.offsetTop);
        
        document.onmousemove = function (ev)
        {
            var ev = ev || event;
            oGC.lineTo(ev.clientX - oC.offsetLeft, ev.clientY - oC.offsetTop);
            oGC.stroke();
        }
        document.onmouseup = function ()
        {
            document.onmousemove = null;
            document.onmouseup = null;
        }
    }
}
</script>
</head>

<body>
    <canvas id="c1" width="400" height="300">
        <span>请升级您的浏览器</span>
    </canvas>
</body>
</html>

 

html5 canvas 鼠标绘制

原文:http://www.cnblogs.com/mayufo/p/4284994.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!