• 阿成
    2019-03-16
    Look via gist: https://gist.github.com/aimergenge/2bcf41ac4c4d2586e48ccd5cec5c9768

    void function () {
      const canvas = document.createElement('canvas')

      canvas.width = document.documentElement.offsetWidth
      canvas.height = document.documentElement.offsetHeight

      canvas.style.position = 'absolute'
      canvas.style.left = '0'
      canvas.style.right = '0'
      canvas.style.top = '0'
      canvas.style.bottom = '0'
      canvas.style.zIndex = '99999'

      document.body.appendChild(canvas)

      const ctx = canvas.getContext('2d')
      draw(ctx, getAllRects())

      function draw (ctx, rects) {
        let i = 0
        ctx.strokeStyle = 'red'
        window.requestAnimationFrame(_draw)

        function _draw () {
          let {x, y, width, height} = rects[i++]
          ctx.strokeRect(x, y, width, height)
          if (i < rects.length) {
            window.requestAnimationFrame(_draw)
          } else {
            console.log('%cDONE', 'background-color: green; color: white; padding: 0.3em 0.5em;')
          }
        }
      }

      function getAllRects () {
        const allElements = document.querySelectorAll('*')
        const rects = []
        const {x: htmlX, y: htmlY} = document.documentElement.getBoundingClientRect()
        allElements.forEach(element => {
          const eachElRects = Array.from(element.getClientRects()).filter(rect => {
            return rect.width || rect.height
          }).map(rect => {
            return {
              x: rect.x - htmlX,
              y: rect.y - htmlY,
              width: rect.width,
              height: rect.height
            }
          })
          rects.push(...eachElRects)
        })
        return rects
      }
    }()
    展开
    
     37
  • welkin
    2019-03-25
    希望作者能讲一下虚拟dom
    还有浏览器的重绘和重排
    以及性能优化,跨域的常用操作(希望细致一点)
    包括一些漏洞和攻击,比如xss,sql注入
    还有一些技术栈,和一些对于前端需要了解的方案,比如离线方案等
     1
     9
  • 痕近痕远
    2019-03-17
    请问老师,如何解决UI自动化测试,定位标签显示元素不可见的问题
    
     3
  • 热心网友好宅💫
    2019-04-25
    一直忍着没问,哪来这么多猫片🤣
    
     1
  • 周飞
    2019-04-07
    <body>
     <canvas id="rect"></canvas>
    <script type="text/javascript">
                 const canvas = document.getElementById('rect');
                 canvas.width =document.documentElement.getBoundingClientRect().width;
                 canvas.height = document.documentElement.getBoundingClientRect().height;
                 canvas.style.position="absolute";
                 canvas.style.top=0;
                 canvas.style.left=0;
                 canvas.style.border='1px solid red';
                 const ctx = canvas.getContext('2d');
                 function travaldom(root){
                   if(root.tagName && root.tagName !=='text' && root.tagName!=='canvas'){
                      const startX = root.getBoundingClientRect().x;
                      const startY = root.getBoundingClientRect().y;
                      const width = root.getBoundingClientRect().width;
                      const height = root.getBoundingClientRect().height;
                      ctx.beginPath();
                      ctx.lineWidth="1";
                      ctx.strokeStyle="blue";
                      ctx.rect(startX,startY,width,height);
                      ctx.stroke();
                   }
                   root.childNodes.forEach(node=>{
                       travaldom(node);
                   });
                 }
                 travaldom(document);
            </script>    
    </body>
    展开
    
     1
  • Russell
    2019-04-03
    emm~~ 我又读了一遍文档,发现了对我来说很关键词,“狭义的”。 那我现在的理解是酱紫的。 广义的理解,就是BOM+DOM,CSSOM是DOM扩展的一部分;如果狭义的认为DOM就是树形结构的话,就可以分出来DOM、CSSOM两部分内容了。 我这样想对么?
    
     1
  • 宋宋
    2019-03-16
    前面讲浏览器渲染时有讲到,CSS经过词法分析和语法分析被解析成一颗抽象语法树。
    这个抽象语法树和CSSOM有什么关联么?因为很多文章都讲CSS经过词法分析和语法分析被解析成CSSOM,感觉很疑惑。
    
     1
  • 。。。
    2019-10-09
    display:inline;的元素会不会产生盒?

    作者回复: 会,而且会产生多个盒

    
    
  • Russell
    2019-04-03
    不对,我觉得我这么理解不对。。。
    
    
  • Russell
    2019-04-03
    这个咋换行啊。。。 不好意思,老师好,我想咨询浏览器API的种类。 我可以认为是,DOM,BOM,CSSOM这几类么?

    作者回复: 这是几个大类,还有好多游离的

    
    
我们在线,来聊聊吧