问答详情
源自:8-6 总结:Canvas高级内容

画布重叠 两个canvas怎么重叠在一起

两个canvas怎么重叠在一起

提问者:慕斯3556369 2017-12-09 10:50

个回答

  • Riddle2000
    2020-02-13 08:58:34

    赞!好用

  • Tom_Kwok
    2017-12-22 02:05:37

      <!-- 上面的HTML结构有误 -->
      <div class="canvas-wrapper">
          <canvas id="canvas-1" class="canvas"></canvas>
          <canvas id="canvas-2" class="canvas"></canvas>
      </div>


  • Tom_Kwok
    2017-12-22 02:03:27

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>canvas重叠</title>
        <style>
          .canvas-wrapper {
            position: relative;
            width: 600px;
            height: 600px;
            border: 1px solid black;
          }
          .canvas {
            width: 400px;
            height: 400px;
          }
          #canvas-1 {
            background-color: #058;
            top: 0;
            left: 0;
          }
          #canvas-2 {
            background-color: red;
            top: 200px;
            left: 200px;
          }
          .canvas {
            position: absolute;
          }
        </style>
      </head>
      <body>
        <div>
          <canvas id="canvas-1"></canvas>
          <canvas id="canvas-2"></canvas>
        </div>
      </body>
    </html>