zoukankan      html  css  js  c++  java
  • canvas 鼠标划线

    <!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>
  • 相关阅读:
    sql 大数据量 的分表操作
    NHibernate 2.0 配置
    NHibernate 之调用存储过程
    k-v-o 扫盲
    320学习笔记 2
    GCD之dispatch queue
    使用KVO体会
    timer,runloop,thread,task小总结
    Run Loop
    iPh oto的删除动画
  • 原文地址:https://www.cnblogs.com/vsmart/p/6692692.html
Copyright © 2011-2022 走看看