• JavaScript实现手动画线


    在网上搜索了一些JavaScript画线的代码,综合了几个例子,作了一些修改和整合,实现了画线的功能,但是只是很简单的功能,只能实现单击画线,双击结束,由于本人初学JS,还不知道怎么实现撤消,及清除。页面代码如下:

    <html xmlns:v="http://www.eglic.com/">
    <head>
    <title>页面画线</title>
    <meta name="ContentType" content="text/html" />
    <meta name="CharSet" content="GB2312" />
    <script language="javascript">
    var Working=false;
    var points = [];
    var lastPoint = {x:0,y:0};
    var line = null;
    document.ondblclick
    =function (){
    if(!Working) return;
    points 
    = [];
    lastPoint 
    = {x:0,y:0}
    Working
    =false;
    }

    document.onclick
    =function (){
    if(!Working){
    Working
    =true;
    }

    var s='<v:line from="'+event.x+','+event.y+'" to="'+event.x+','+event.y+'" style="position:absolute;left:0px;top:0px;"></v:line>';
    lastPoint.x 
    = event.x;
    lastPoint.y 
    = event.y;
    points.push( 
    {x:event.x,y:event.y} );
    document.getElementById(
    "show").innerHTML = "X:"+ event.x + " Y:" + event.y;
    document.getElementById(
    "show").style.display="";
    var o=document.createElement(s);
    document.body.insertAdjacentElement(
    'BeforeEnd',o);
    line 
    = o;
    }

    document.onmousemove
    =function (){
    if(!Working) return;
    line.to 
    = event.x + "," + event.y;
    document.getElementById(
    "dshow").innerHTML = "X:"+ event.x + " Y:" + event.y;
    document.getElementById(
    "dshow").style.display="";
    }


    </script>
    <style type="text/css">
    v\:
    * {behavior:url(#default#VML);}
    </style>
    </head>
    <body>


     
    <div id="show" style="border:5px solid #000;200px;height:30px;line-height:30px;text-align:center;display:none"> 
    </div>
    <div id="dshow" style="border:5px solid #000;200px;height:30px;line-height:30px;text-align:center;display:none"> 
    </div>
    </body>
    </html> 
  • 相关阅读:
    React Virtual Dom 与 Diff
    打造前端CI/CD工作流
    webpack-chain明细
    React项目中实现多语言支持
    【WPF】大量Canvas转换为本地图片遇到的问题
    【C#】【分享】 XX分钟学会C#
    【WPF】一些拖拽实现方法的总结(Window,UserControl)
    【WPF】 InkCanvas 书写毛笔效果
    js中this指向问题
    js原型浅谈理解
  • 原文地址:https://www.cnblogs.com/glacierh/p/1263591.html
Copyright © 2020-2023  润新知