• JavaScript 制作简单画板


    js原生我不太懂,可能写的比较垃圾,主要是想解决禁止拖拽和批量绑定事件,以及生成页面元素

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>画画</title>
    </head>
    <style>
        #box{
            float: left;
            border: 1px solid black;
        }
        .cell{
            background: pink;
             5px;
            height: 5px;
            float: left;
        }
        .cell_c{
            clear:left;
        }
    </style>
    <body>
        <div id="box" onmouseup="end_hua()" onmousedown="start_hua()"></div>
        <script>
            let height = 100;
            let width = 100;
            let kaiguan = 0;
            for(var i=0;i<height;i++){
                for(var j=0;j<width;j++){
                    let d = document.createElement("div");
                    d.ondragstart = function(){return false;};//禁用拖拽
                    d.onmousemove = function(){hua(d)};
                    d.className = "cell";
                    if(j==0){
                        d.className = "cell cell_c";
                    }
                    document.getElementById("box").appendChild(d);
                }
            }
            
            function start_hua(){
                kaiguan = 1;
                console.log("开始")
            }
            function end_hua(){
                kaiguan = 0;
                console.log("结束")
            }
            function hua(e){
                if(kaiguan==1){
                    e.style.backgroundColor="black"
                }
                // console.log()
            }
        </script>
    </body>
    </html>
    

      

  • 相关阅读:
    生成函数代替伯努利数
    关于费用流
    GDOI注意事项
    计算几何 学习笔记
    jzoj5370
    图上的游戏
    小学生语文题
    arcane
    P2305 [NOI2014] 购票
    P3512 [POI2010]PIL-Pilots
  • 原文地址:https://www.cnblogs.com/zonglonglong/p/12354494.html
Copyright © 2020-2023  润新知