首页 > 其他 > 详细

canvas 鼠标划线

时间:2017-04-11 14:01:38      阅读:350      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>canvas</title>
<style>
body{background: #000;}
#c1{background: #fff;}
</style>
<script>
window.onload = function(){
    var oc = document.getElementById(‘c1‘);
    var ogc = oc.getContext(‘2d‘);
 
    oc.onmousedown = function(ev){
        var ev = ev || window.event;
        ogc.moveTo(ev.clientX-oc.offsetLeft,ev.clientY-oc.offsetTop);
        document.onmousemove=function(ev){
            var ev = ev || window.event;
            ogc.lineTo(ev.clientX-oc.offsetLeft,ev.clientY-oc.offsetTop);
            ogc.stroke();
        }
 
        document.onmouseup = function(){
            document.onmousemove = null;
            document.onmousedown = null;
        }
    }
 
    ogc.stroke();
 
}
</script>
</head>
<body>
<canvas id="c1" width="400" height="400"></canvas>
</body>
</html>

canvas 鼠标划线

原文:http://www.cnblogs.com/vsmart/p/6692692.html

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