test123 templatediv classcontainer!-- div覆盖 iframe --divrefdragDivclassdrag-div:style{left: position.x px,top: position.y px,backgroundColor: isDragging ? #ff6b6b : rgba(0, 0, 0, 0.3),pointerEvents: isDragging ? auto : none}拖拽/div!-- iframe下层被 div 覆盖 --iframe refiframeRef srcabout:blank classiframe-content/iframe/div/templatescript setupimport { ref, onMounted, onUnmounted, nextTick } from vue;const dragDiv ref(null);const iframeRef ref(null);const isDragging ref(false);const position ref({ x: 0, y: 0 });const dragOffset ref({ x: 0, y: 0 });// 检测鼠标是否在 iframe 的 .checkarea 区域的按钮上const isOnIframeButton (e) {const iframe iframeRef.value;if (!iframe) return false;try {// 获取 iframe 的内部文档const iframeDoc iframe.contentDocument || iframe.contentWindow?.document;if (!iframeDoc) return false;// 找到 .checkarea 区域const checkarea iframeDoc.querySelector(.checkarea);if (!checkarea) return false;// 获取 .checkarea 的边界矩形相对于视口const checkareaRect checkarea.getBoundingClientRect();// 如果鼠标不在 .checkarea 区域内直接返回 falseif (e.clientX checkareaRect.left || e.clientX checkareaRect.right ||e.clientY checkareaRect.top || e.clientY checkareaRect.bottom) {return false;}// 在 .checkarea 内部查找所有按钮const buttons checkarea.querySelectorAll(button);for (const btn of buttons) {const rect btn.getBoundingClientRect();if (e.clientX rect.left e.clientX rect.right e.clientY rect.top e.clientY rect.bottom) {return true;}}return false;} catch (error) {// 跨域 iframe 会报错此时无法检测console.warn(无法访问 iframe 内容可能跨域:, error);return false;}};// 检测鼠标是否在 div 上const isOnDiv (e) {const div dragDiv.value;if (!div) return false;const rect div.getBoundingClientRect();return e.clientX rect.left e.clientX rect.right e.clientY rect.top e.clientY rect.bottom;};// 全局鼠标按下const onMouseDown (e) {if (e.button ! 0) return;if (isOnDiv(e)) {// 如果点击在 iframe 的 .checkarea 按钮上不启动拖拽if (isOnIframeButton(e)) return;const div dragDiv.value;const rect div.getBoundingClientRect();isDragging.value true;dragOffset.value {x: e.clientX - rect.left,y: e.clientY - rect.top};e.preventDefault();}};// 全局鼠标移动const onMouseMove (e) {if (!isDragging.value) return;const div dragDiv.value;if (!div) return;let newX e.clientX - dragOffset.value.x;let newY e.clientY - dragOffset.value.y;newX Math.max(0, Math.min(newX, window.innerWidth - div.offsetWidth));newY Math.max(0, Math.min(newY, window.innerHeight - div.offsetHeight));position.value { x: newX, y: newY };};// 全局鼠标释放const onMouseUp () {if (isDragging.value) {isDragging.value false;}};// 初始化位置const initPosition () {const div dragDiv.value;if (!div) return;position.value {x: (window.innerWidth - div.offsetWidth) / 2,y: (window.innerHeight - div.offsetHeight) / 2};};onMounted(() {initPosition();document.addEventListener(mousedown, onMouseDown);document.addEventListener(mousemove, onMouseMove);document.addEventListener(mouseup, onMouseUp);});onUnmounted(() {document.removeEventListener(mousedown, onMouseDown);document.removeEventListener(mousemove, onMouseMove);document.removeEventListener(mouseup, onMouseUp);});/scriptstyle scoped* {margin: 0;padding: 0;box-sizing: border-box;}.container {width: 100vw;height: 100vh;position: relative;background: #f0f0f0;}.iframe-content {width: 100%;height: 100%;border: none;z-index: 1;position: relative;}.drag-div {position: absolute;width: 300px;height: 200px;background: rgba(0, 0, 0, 0.3);backdrop-filter: blur(8px);border-radius: 16px;border: 2px solid rgba(255, 255, 255, 0.1);z-index: 2;cursor: grab;display: flex;align-items: center;justify-content: center;color: white;font-size: 18px;font-weight: 500;user-select: none;transition: background-color 0.2s ease;pointer-events: none;}.drag-div.dragging {cursor: grabbing;}/style

相关新闻

最新新闻

【1980-2025】中科院30m土地利用/覆盖数据|全国|TIFF

【1980-2025】中科院30m土地利用/覆盖数据|全国|TIFF

🔍 数据简介 本次分享1980-2025年全国30m分辨率土地利用/土地覆盖栅格数据(CNLUCC),由中科院地理科学与资源研究所研制,权威基准数据。 数据覆盖全国全域,分为两个标准版本,并已更新至2023/2025…

2026/7/15 0:08:32
【1979-2026】全国GDP栅格数据|1km分辨率

【1979-2026】全国GDP栅格数据|1km分辨率

🔍 数据简介 本次分享1979-2026年全国1km分辨率GDP空间分布栅格数据,由中科院资源环境科学数据中心研制,权威可靠。 数据集覆盖全国全域,1992-2019年逐年完整,关键年份(1995/2000/2005/2010/2015/2019/2020…

2026/7/15 0:08:32
【1975-2026】全国水系水路数据|河流/水库/运河|SHP矢量

【1975-2026】全国水系水路数据|河流/水库/运河|SHP矢量

🔍 数据简介 本次分享1975-2026年全国高精度水系水路矢量数据,覆盖全国全域,包含河流、水系、水库、运河、湿地、冰川、沟渠等全类别水文要素。 数据集包含双层矢量图层,字段分类清晰、要素齐全,支持2013-2026逐年完整…

2026/7/15 0:08:32
【1982-2026】全国高精度建筑轮廓|村级精度|SHP矢量

【1982-2026】全国高精度建筑轮廓|村级精度|SHP矢量

🔍 数据简介 本次分享1982-2026年全国村级精度建筑轮廓矢量数据,覆盖全国各省市区县,到村级别精细,为2026年最新实时采集成果,非网传仅60/77个城市的老旧数据。 数据含带高度/不带高度双版本,单体建筑边界精…

2026/7/15 0:08:32
【LINUX】驱动

【LINUX】驱动

【LINUX驱动】【字符设备】【中断】【Platform】【网课 设备树】【GPIO】【PINCTRL】【INPUT】【IIC】【SPI】【网络驱动】【屏幕驱动】【一 设备树】【二 内核模块编译】【三 基本驱动框架】【四 Platform总线设备驱动框架】【五 驱动子系统】【六 综合】

2026/7/15 0:08:32
AI框架决定企业AI能走多远

AI框架决定企业AI能走多远

企业AI建设的第一性原理 企业搞AI,最关键的决定是什么?不是选哪家大模型,不是先做哪个场景,不是招多少AI人才——而是选哪个AI开发框架。 为什么?因为框架决定了企业AI能力的"天花板"。选对了框架&#xff0…

2026/7/15 0:03:31

月新闻