2025-09-09 07:33:51 +08:00
|
|
|
|
<!DOCTYPE html>
|
2025-09-09 07:46:47 +08:00
|
|
|
|
<html lang="en">
|
2025-09-09 07:33:51 +08:00
|
|
|
|
<head>
|
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
2025-09-09 07:46:47 +08:00
|
|
|
|
<title>箭头动画</title>
|
2025-09-09 07:33:51 +08:00
|
|
|
|
<style>
|
2025-09-09 14:41:54 +08:00
|
|
|
|
body { margin: 0; padding: 0; height: 100vh; display: flex; overflow: hidden; }
|
|
|
|
|
.background-container { position: relative; flex: 1; height: 100vh; background-image: url('D:\\dsWork\\dsProject\\dsLightRag\\XingJun\\background.png'); background-position: center; background-repeat: no-repeat; background-size: contain; z-index: 1; }
|
|
|
|
|
.control-panel { width: 200px; background-color: #fff; border-left: 1px solid #ccc; padding: 20px; height: 100vh; box-sizing: border-box; z-index: 2; overflow-y: auto; }
|
|
|
|
|
.control-section { margin-bottom: 30px; }
|
|
|
|
|
.control-section h3 { margin-top: 0; padding-bottom: 10px; border-bottom: 1px solid #eee; }
|
|
|
|
|
.image-selector { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 15px; }
|
|
|
|
|
.image-btn { width: 70px; height: 70px; border: 2px solid #ddd; border-radius: 4px; cursor: pointer; background-size: contain; background-repeat: no-repeat; background-position: center; transition: all 0.2s; }
|
|
|
|
|
.image-btn:hover { border-color: #4CAF50; transform: scale(1.05); }
|
|
|
|
|
.image-btn:active { transform: scale(0.98); }
|
|
|
|
|
.arrow-container { position: absolute; pointer-events: auto; }
|
|
|
|
|
.arrow-image { width: 155px; height: 173px; background-size: contain; background-repeat: no-repeat; cursor: move; }
|
|
|
|
|
.save-btn { width: 100%; padding: 10px; background-color: #4CAF50; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; margin-top: 20px; }
|
|
|
|
|
.save-btn:hover { background-color: #45a049; }
|
|
|
|
|
.arrow-text { position: absolute; top: '100%'; left: '50%'; transform: translateX(-50%); margin-top: '-5px'; font-weight: bold; color: red; font-size: 16px; white-space: nowrap; text-align: center; width: 100%; background-color: rgba(255, 255, 255, 0.8); padding: 3px 8px; border-radius: 4px; }
|
|
|
|
|
#contextMenu { position: absolute; display: none; background: white; border: 1px solid #ccc; padding: 5px; z-index: 9999; }
|
|
|
|
|
#deleteArrow { padding: 3px 10px; cursor: pointer; }
|
2025-09-09 07:33:51 +08:00
|
|
|
|
</style>
|
2025-09-09 14:58:52 +08:00
|
|
|
|
<style>
|
|
|
|
|
/* 新增红点样式 */
|
|
|
|
|
.center-dot {
|
|
|
|
|
position: absolute;
|
|
|
|
|
width: 8px;
|
|
|
|
|
height: 8px;
|
|
|
|
|
background: red;
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
transform: translate(-50%, -50%);
|
|
|
|
|
pointer-events: none;
|
|
|
|
|
z-index: 5;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
2025-09-09 07:33:51 +08:00
|
|
|
|
</head>
|
|
|
|
|
<body>
|
2025-09-09 14:41:54 +08:00
|
|
|
|
<div class="background-container"></div>
|
2025-09-09 14:07:51 +08:00
|
|
|
|
<div class="control-panel">
|
|
|
|
|
<div class="control-section">
|
|
|
|
|
<h3>增加箭头</h3>
|
|
|
|
|
<div class="image-selector">
|
|
|
|
|
<div class="image-btn" data-image="./1.png" style="background-image: url('./1.png');"></div>
|
|
|
|
|
<div class="image-btn" data-image="./2.png" style="background-image: url('./2.png');"></div>
|
|
|
|
|
<div class="image-btn" data-image="./3.png" style="background-image: url('./3.png');"></div>
|
|
|
|
|
<div class="image-btn" data-image="./4.png" style="background-image: url('./4.png');"></div>
|
|
|
|
|
<div class="image-btn" data-image="./5.png" style="background-image: url('./5.png');"></div>
|
2025-09-09 14:34:13 +08:00
|
|
|
|
<div class="image-btn" data-image="./6.png" style="background-image: url('./6.png');"></div>
|
2025-09-09 14:07:51 +08:00
|
|
|
|
</div>
|
2025-09-09 14:09:02 +08:00
|
|
|
|
<button class="save-btn" id="savePositionsBtn">保存位置</button>
|
2025-09-09 07:39:54 +08:00
|
|
|
|
</div>
|
2025-09-09 07:33:51 +08:00
|
|
|
|
</div>
|
2025-09-09 14:41:54 +08:00
|
|
|
|
<div id="contextMenu"><div id="deleteArrow">删除箭头</div></div>
|
2025-09-09 07:33:51 +08:00
|
|
|
|
|
2025-09-09 14:07:51 +08:00
|
|
|
|
<script>
|
2025-09-09 14:41:54 +08:00
|
|
|
|
// 修复核心:整理所有JS代码到单个script标签内
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
|
const backgroundContainer = document.querySelector('.background-container');
|
|
|
|
|
const imageButtons = document.querySelectorAll('.image-btn');
|
|
|
|
|
const saveBtn = document.getElementById('savePositionsBtn');
|
|
|
|
|
const contextMenu = document.getElementById('contextMenu');
|
|
|
|
|
const deleteArrow = document.getElementById('deleteArrow');
|
|
|
|
|
let selectedArrow = null;
|
|
|
|
|
|
|
|
|
|
// 加载保存的元素
|
|
|
|
|
loadAllElements();
|
|
|
|
|
|
|
|
|
|
// 绑定箭头按钮事件
|
|
|
|
|
imageButtons.forEach(button => {
|
|
|
|
|
button.addEventListener('click', () => {
|
|
|
|
|
const imagePath = button.getAttribute('data-image');
|
|
|
|
|
addImageToContainer(imagePath);
|
|
|
|
|
});
|
2025-09-09 14:07:51 +08:00
|
|
|
|
});
|
|
|
|
|
|
2025-09-09 14:41:54 +08:00
|
|
|
|
// 保存按钮事件
|
|
|
|
|
saveBtn.addEventListener('click', saveAllElements);
|
2025-09-09 14:34:13 +08:00
|
|
|
|
|
2025-09-09 14:41:54 +08:00
|
|
|
|
// 右键菜单事件
|
|
|
|
|
deleteArrow.addEventListener('click', function() {
|
|
|
|
|
if (selectedArrow) {
|
|
|
|
|
selectedArrow.remove();
|
|
|
|
|
saveAllElements();
|
|
|
|
|
contextMenu.style.display = 'none';
|
|
|
|
|
selectedArrow = null;
|
2025-09-09 14:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2025-09-09 14:07:51 +08:00
|
|
|
|
|
2025-09-09 14:41:54 +08:00
|
|
|
|
// 点击空白处关闭菜单
|
|
|
|
|
document.addEventListener('click', function() {
|
|
|
|
|
contextMenu.style.display = 'none';
|
|
|
|
|
selectedArrow = null;
|
2025-09-09 14:16:09 +08:00
|
|
|
|
});
|
2025-09-09 14:09:02 +08:00
|
|
|
|
|
2025-09-09 14:41:54 +08:00
|
|
|
|
// 添加箭头函数
|
|
|
|
|
function addImageToContainer(imagePath, position = null, textContent = '') {
|
|
|
|
|
const container = document.createElement('div');
|
|
|
|
|
container.className = 'arrow-container';
|
|
|
|
|
container.dataset.imagePath = imagePath;
|
|
|
|
|
|
|
|
|
|
const newImage = document.createElement('div');
|
|
|
|
|
newImage.className = 'arrow-image';
|
|
|
|
|
newImage.style.backgroundImage = `url('${imagePath}')`;
|
|
|
|
|
|
|
|
|
|
container.appendChild(newImage);
|
|
|
|
|
|
|
|
|
|
// 添加文字元素
|
|
|
|
|
if (textContent) {
|
|
|
|
|
const textElement = document.createElement('div');
|
|
|
|
|
textElement.className = 'arrow-text';
|
|
|
|
|
textElement.textContent = textContent;
|
|
|
|
|
container.dataset.text = textContent;
|
|
|
|
|
container.appendChild(textElement);
|
2025-09-09 14:09:02 +08:00
|
|
|
|
}
|
2025-09-09 14:16:09 +08:00
|
|
|
|
|
2025-09-09 14:41:54 +08:00
|
|
|
|
// 设置位置
|
|
|
|
|
if (position) {
|
|
|
|
|
container.style.left = position.left;
|
|
|
|
|
container.style.top = position.top;
|
|
|
|
|
} else {
|
|
|
|
|
const x = Math.random() * (backgroundContainer.offsetWidth - 155);
|
|
|
|
|
const y = Math.random() * (backgroundContainer.offsetHeight - 173);
|
|
|
|
|
container.style.left = `${x}px`;
|
|
|
|
|
container.style.top = `${y}px`;
|
|
|
|
|
}
|
2025-09-09 14:16:09 +08:00
|
|
|
|
|
2025-09-09 14:41:54 +08:00
|
|
|
|
// 双击编辑文字
|
|
|
|
|
container.addEventListener('dblclick', (e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
const currentText = container.dataset.text || '';
|
|
|
|
|
const textContent = prompt('请输入文字:', currentText);
|
|
|
|
|
if (textContent !== null) {
|
|
|
|
|
if (textContent.trim() === '') {
|
|
|
|
|
container.querySelector('.arrow-text')?.remove();
|
|
|
|
|
delete container.dataset.text;
|
|
|
|
|
} else {
|
|
|
|
|
let textElement = container.querySelector('.arrow-text');
|
|
|
|
|
if (!textElement) {
|
|
|
|
|
textElement = document.createElement('div');
|
|
|
|
|
textElement.className = 'arrow-text';
|
|
|
|
|
container.appendChild(textElement);
|
|
|
|
|
}
|
|
|
|
|
textElement.textContent = textContent;
|
|
|
|
|
container.dataset.text = textContent;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-09-09 14:16:09 +08:00
|
|
|
|
|
2025-09-09 14:41:54 +08:00
|
|
|
|
// 右键菜单支持
|
|
|
|
|
container.addEventListener('contextmenu', function(e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
selectedArrow = this;
|
|
|
|
|
contextMenu.style.left = `${e.clientX}px`;
|
|
|
|
|
contextMenu.style.top = `${e.clientY}px`;
|
|
|
|
|
contextMenu.style.display = 'block';
|
|
|
|
|
});
|
2025-09-09 14:16:09 +08:00
|
|
|
|
|
2025-09-09 14:41:54 +08:00
|
|
|
|
// 拖拽功能
|
|
|
|
|
makeElementDraggable(container);
|
|
|
|
|
backgroundContainer.appendChild(container);
|
|
|
|
|
return container;
|
|
|
|
|
}
|
2025-09-09 14:34:13 +08:00
|
|
|
|
|
2025-09-09 14:41:54 +08:00
|
|
|
|
// 拖拽实现
|
|
|
|
|
function makeElementDraggable(element) {
|
|
|
|
|
let isDragging = false, offsetX, offsetY;
|
|
|
|
|
element.addEventListener('mousedown', (e) => {
|
|
|
|
|
if (e.button === 2) return; // 忽略右键
|
|
|
|
|
isDragging = true;
|
|
|
|
|
const rect = element.getBoundingClientRect();
|
|
|
|
|
offsetX = e.clientX - rect.left;
|
|
|
|
|
offsetY = e.clientY - rect.top;
|
|
|
|
|
element.style.zIndex = '10';
|
|
|
|
|
});
|
2025-09-09 14:34:13 +08:00
|
|
|
|
|
2025-09-09 14:41:54 +08:00
|
|
|
|
document.addEventListener('mousemove', (e) => {
|
|
|
|
|
if (!isDragging) return;
|
|
|
|
|
const x = e.clientX - offsetX;
|
|
|
|
|
const y = e.clientY - offsetY;
|
|
|
|
|
element.style.left = `${x}px`;
|
|
|
|
|
element.style.top = `${y}px`;
|
|
|
|
|
});
|
2025-09-09 14:34:13 +08:00
|
|
|
|
|
2025-09-09 14:41:54 +08:00
|
|
|
|
document.addEventListener('mouseup', () => {
|
|
|
|
|
if (isDragging) {
|
|
|
|
|
isDragging = false;
|
|
|
|
|
element.style.zIndex = '2';
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-09-09 14:07:51 +08:00
|
|
|
|
}
|
2025-09-09 14:34:13 +08:00
|
|
|
|
|
2025-09-09 14:41:54 +08:00
|
|
|
|
// 保存/加载功能
|
|
|
|
|
function saveAllElements() {
|
|
|
|
|
const elements = [];
|
|
|
|
|
document.querySelectorAll('.arrow-container').forEach(container => {
|
|
|
|
|
elements.push({
|
|
|
|
|
type: 'arrow',
|
|
|
|
|
imagePath: container.dataset.imagePath,
|
|
|
|
|
text: container.dataset.text || '',
|
|
|
|
|
left: container.style.left,
|
|
|
|
|
top: container.style.top
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
localStorage.setItem('mapElements', JSON.stringify(elements));
|
|
|
|
|
alert('保存成功!');
|
2025-09-09 14:07:51 +08:00
|
|
|
|
}
|
2025-09-09 14:34:13 +08:00
|
|
|
|
|
2025-09-09 14:41:54 +08:00
|
|
|
|
function loadAllElements() {
|
|
|
|
|
const savedData = localStorage.getItem('mapElements');
|
|
|
|
|
if (savedData) {
|
|
|
|
|
try {
|
|
|
|
|
JSON.parse(savedData).forEach(element => {
|
|
|
|
|
if (element.type === 'arrow') {
|
|
|
|
|
addImageToContainer(element.imagePath, {left: element.left, top: element.top}, element.text);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} catch (e) { console.error('加载失败:', e); }
|
|
|
|
|
}
|
2025-09-09 14:07:51 +08:00
|
|
|
|
}
|
2025-09-09 14:41:54 +08:00
|
|
|
|
});
|
2025-09-09 14:07:51 +08:00
|
|
|
|
</script>
|
2025-09-09 14:58:52 +08:00
|
|
|
|
<div class="control-panel">
|
|
|
|
|
<div class="control-section">
|
|
|
|
|
<!-- 在按钮区域新增标记按钮 -->
|
|
|
|
|
<button class="save-btn" id="markCenterBtn">标记中心点</button>
|
|
|
|
|
<!-- 原有其他按钮保持不变 -->
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
|
// 新增中心点相关代码
|
|
|
|
|
const markCenterBtn = document.getElementById('markCenterBtn');
|
|
|
|
|
const backgroundContainer = document.querySelector('.background-container');
|
|
|
|
|
let centerDot = null;
|
|
|
|
|
|
|
|
|
|
// 标记中心点功能
|
|
|
|
|
markCenterBtn.addEventListener('click', function() {
|
|
|
|
|
// 移除旧点
|
|
|
|
|
if (centerDot) {
|
|
|
|
|
centerDot.remove();
|
|
|
|
|
centerDot = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建新点
|
|
|
|
|
function handleMapClick(e) {
|
|
|
|
|
const rect = backgroundContainer.getBoundingClientRect();
|
|
|
|
|
const x = e.clientX - rect.left;
|
|
|
|
|
const y = e.clientY - rect.top;
|
|
|
|
|
|
|
|
|
|
centerDot = document.createElement('div');
|
|
|
|
|
centerDot.className = 'center-dot';
|
|
|
|
|
centerDot.style.left = x + 'px';
|
|
|
|
|
centerDot.style.top = y + 'px';
|
|
|
|
|
|
|
|
|
|
backgroundContainer.appendChild(centerDot);
|
|
|
|
|
backgroundContainer.removeEventListener('click', handleMapClick);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
backgroundContainer.addEventListener('click', handleMapClick);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 原有JavaScript代码保持不变
|
|
|
|
|
});
|
|
|
|
|
</script>
|
2025-09-09 07:33:51 +08:00
|
|
|
|
</body>
|
2025-09-09 13:47:24 +08:00
|
|
|
|
</html>
|
|
|
|
|
|