zoukankan      html  css  js  c++  java
  • js小练习——在页面中点击哪里,哪里出现div(圆)

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>点哪,哪出15*15的圆型div</title>
    <style type="text/css">
    html,body{
    height: 100%;
    margin: 0;
    padding: 0;
    }
    .yuan {
    16px;
    height: 16px;
    border-radius: 50%;
    position: absolute;
    }
    </style>
    </head>
    <body>
    <script>
    /**
    * 点哪 哪出15*15的圆型div
    */
    document.body.addEventListener('click', function (e) {
    var div = document.createElement('div'); //创建div元素
    var className = document.createAttribute('class');//创建class属性
    className.value = 'yuan';//属性赋值
    div.style.left = e.clientX - 16/2 + 'px';
    div.style.top = e.clientY - 16/2 + 'px';
    div.setAttributeNode(className);//设置属性节点
    div.style.backgroundColor = '#' + parseInt(0xffffff * Math.random()).toString(16);//随机背景颜色
    document.body.appendChild(div);//给body添加元素div
    })

    </script>
    </body>
    </html>
  • 相关阅读:
    寒假作业3
    寒假作业2
    寒假作业
    Binary Indexed Tree
    Quick Union
    Prim's Algorithm & Kruskal's algorithm
    面向对象阶段总结 | 肆
    面向对象阶段总结 | 叁
    面向对象阶段总结 | 贰
    面向对象阶段总结 | 壹
  • 原文地址:https://www.cnblogs.com/chuangzi/p/6754135.html
Copyright © 2011-2022 走看看