<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] ### 效果展示: ![](http://elb-791125809.cn-northwest-1.elb.amazonaws.com.cn:5335/xdata/xdata-sh-firstdept/front-end/note-book/raw/ca3fe1a8a3999133d8071bcad13c7f2f16965460/%E5%AD%90%E5%85%83%E7%B4%A0%E5%9C%A8%E5%AE%B9%E5%99%A8%E8%8C%83%E5%9B%B4%E5%86%85%E6%8B%96%E5%8A%A8/.image/1.gif) ### 實現思路: ~~~ 找一個空箱子和一塊小于箱子紙板,用筆插穿紙板,然后在箱子里面筆在箱底隨便畫,能畫出的的范圍肯定是有限的; 容器相當于箱子,子元素相當于紙板,鼠標位置相當于筆,然后就有了鼠標能移動的范圍 ~~~ ### 實現原理: ~~~ <!DOCTYPE html> <html lang="en"> <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>Document</title> <style> html,body,.father {margin: 0;height: 100%;width: 100%;} body{display: flex;justify-content: center; align-items: center;} .contain{ position: relative; height: 90%;width: 90%;border: black 1px solid;background-color: rgba(205, 135, 222, 0.767);} .child {position: absolute;height: 200px;width: 200px;border: black 1px solid;background-color: coral;} </style> </head> <body> <div class="contain"> <div id="father" class="father"> <div id="child" class="child" onmousedown="mouseDown(event)" ></div> </div> </div> <script> let child = document.querySelector('#child') const mouseDown = evt => { let mBounds = mouseBounds( evt, child.getBoundingClientRect(), document.querySelector('#father').getBoundingClientRect() ) document.onmousemove = function(ev) { let pt = calcPositon(ev, mBounds) child.style.left = pt.left + 'px' child.style.top = pt.top + 'px' child.style.opacity = 0.9 child.style.cursor = 'move' } document.onmouseup = function() { document.onmousemove = null document.onmouseup = null child.style.opacity = 1 child.style.cursor = 'default' } } const calcPositon = (pt, bounds) => { const left = (pt.x > bounds.left && pt.x < bounds.right ? pt.x : pt.x >= bounds.right ? bounds.right : bounds.left) - bounds.offsetX const top = (pt.y > bounds.top && pt.y < bounds.bottom ? pt.y : pt.y >= bounds.bottom ? bounds.bottom : bounds.top) - bounds.offsetY return { left, top } } /** * 鼠標可以移動的范圍 * pt:鼠標按下的點 * compRact:要移動組件的矩形對象 * containerRact:容器的矩形對象 * return 的范圍為瀏覽器窗口中的范圍(offset為左上角相對于瀏覽器的偏移) */ const mouseBounds = (pt, compRact, containerRact) => { return { left: containerRact.left + (pt.x - compRact.left), right: containerRact.right - (compRact.right - pt.x), top: containerRact.top + (pt.y - compRact.top), bottom: containerRact.bottom - (compRact.bottom - pt.y), offsetX: containerRact.left + (pt.x - compRact.left), offsetY: containerRact.top + (pt.y - compRact.top) } } </script> </body> </html> ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看