天下无坑

天下无坑


在指定对象范围内移动

<pre><code class="language-js">// 只能在指定层上移动 function moveOnLayer(oLayer, event){ if(!event.target) return const o = event.target oLayer.setCoords() let {left, top, width, height} = oLayer.getBoundingRect() if(o.currentHeight &gt; height || o.currentWidth &gt; width) return o.setCoords() let {left: l, top: t, width: w, height: h} = o.getBoundingRect() // 上 if(t &lt; top){ o.top = Math.max(o.top, o.top - t, top) } // 左 if(l &lt; left){ o.left = Math.max(o.left, o.left - l, left) } // 下 if(t + h &gt; top + height){ o.top = Math.min(o.top, height - h + o.top - t) + top } // 右 if(l + w &gt; left + width){ o.left = Math.min(o.left, width - w + o.left - l) + left } }</code></pre>

页面列表

ITEM_HTML