Anonymous
Линия лидера проходит через элементы
Сообщение
Anonymous » 23 окт 2025, 09:20
Я пытаюсь создать приложение, в котором можно было бы задать объяснение для каждого слова. Большая проблема заключается в том, что линия выноски проходит через мой текст, а MiddleAnchor не работает на пути сетки. Я хочу сохранить путь сетки и не менять его ни на что другое.
Вот как он выглядит сейчас.
Код: Выделить всё
const form = document.querySelector('form');
const input = document.getElementById('search');
const wordcontainer = document.getElementById('words-container');
const descriptioncontainer = document.getElementById('description-container');
form.addEventListener('submit', (event) => {
event.preventDefault();
const value = input.value.trim();
wordcontainer.innerHTML = "";
descriptioncontainer.innerHTML = "";
if (value) {
const words = value.split(/\s+/);
const half = Math.ceil(words.length / 2);
words.forEach((word, index) => {
const isFirstHalf = index < half;
createWordElement(word, index, isFirstHalf);
});
}
});
function createWordElement(text, index, isFirstHalf) {
const h1 = document.createElement('h1');
h1.textContent = text;
h1.id = 'word-output-' + index;
h1.style.margin = "10px";
h1.style.position = "relative";
wordcontainer.appendChild(h1);
const h4 = document.createElement('h4');
h4.textContent = "LOREM IPSUM";
h4.id = "description-" + index;
h4.style.padding = "10px 5px";
h4.style.border = "1px solid #ccc";
h4.style.borderRadius = "4px";
h4.style.position = "relative"
h4.style.left = "50%"
descriptioncontainer.appendChild(h4);
setTimeout(() => {
const options = {
path: "grid",
startSocket: "bottom",
endSocket: isFirstHalf ? "left" : "right",
size: 2,
color: "black",
startSocketGravity: 0.1,
endSocketGravity: 30 * index,
endPlug: "behind"
};
new LeaderLine(
document.getElementById('word-output-' + index),
document.getElementById('description-' + index),
options
);
}, 50);
}
Подробнее здесь:
https://stackoverflow.com/questions/797 ... h-elements
1761200411
Anonymous
Я пытаюсь создать приложение, в котором можно было бы задать объяснение для каждого слова. Большая проблема заключается в том, что линия выноски проходит через мой текст, а MiddleAnchor не работает на пути сетки. Я хочу сохранить путь сетки и не менять его ни на что другое. Вот как он выглядит сейчас. [img]https://i.sstatic.net/1RJ1U73L.png[/img] [code]const form = document.querySelector('form'); const input = document.getElementById('search'); const wordcontainer = document.getElementById('words-container'); const descriptioncontainer = document.getElementById('description-container'); form.addEventListener('submit', (event) => { event.preventDefault(); const value = input.value.trim(); wordcontainer.innerHTML = ""; descriptioncontainer.innerHTML = ""; if (value) { const words = value.split(/\s+/); const half = Math.ceil(words.length / 2); words.forEach((word, index) => { const isFirstHalf = index < half; createWordElement(word, index, isFirstHalf); }); } }); function createWordElement(text, index, isFirstHalf) { const h1 = document.createElement('h1'); h1.textContent = text; h1.id = 'word-output-' + index; h1.style.margin = "10px"; h1.style.position = "relative"; wordcontainer.appendChild(h1); const h4 = document.createElement('h4'); h4.textContent = "LOREM IPSUM"; h4.id = "description-" + index; h4.style.padding = "10px 5px"; h4.style.border = "1px solid #ccc"; h4.style.borderRadius = "4px"; h4.style.position = "relative" h4.style.left = "50%" descriptioncontainer.appendChild(h4); setTimeout(() => { const options = { path: "grid", startSocket: "bottom", endSocket: isFirstHalf ? "left" : "right", size: 2, color: "black", startSocketGravity: 0.1, endSocketGravity: 30 * index, endPlug: "behind" }; new LeaderLine( document.getElementById('word-output-' + index), document.getElementById('description-' + index), options ); }, 50); }[/code] [code] [/code] Подробнее здесь: [url]https://stackoverflow.com/questions/79797080/leader-line-goes-through-elements[/url]