美文网首页
canvas画线

canvas画线

作者: 耍帅oldboy | 来源:发表于2020-09-07 15:56 被阅读0次
    <canvas id="c1" width="600" height="400"></canvas>
     var c1=document.getElementById('c1');
     var ctx=c1.getContext('2d');
     c1.onmousedown = unciton(ev){
        var _this = this;
        var x = ev.pageX - this.offsetLeft;
        var y = ev.pageY - this.offsetTop;
        ctx.moveTo(x,y);
        document.onmousemove = function(ev){
                var x = ev.pageX - this.offsetLeft;
                var y = ev.pageY - this.offsetTop;
                ctx.lineTo(x,y);
                ctx.stroke();
        };
        document.onmouseup = function(){
            document.onmousemove = null;
            document.onmouseup = null;
        };
     };
    

    相关文章

      网友评论

          本文标题:canvas画线

          本文链接:https://www.haomeiwen.com/subject/yaclektx.html