createElement.js 887 Bytes
import './style.less';

const id = 'measure-tip';
export const createMeasureElement = (scenepPosition, text) => {
    const dom = document.getElementById(id);
    if (dom) {
        dom.innerHTML = text;
        dom.style.left = `${scenepPosition.x - 39.5}px`;
        dom.style.top = `${scenepPosition.y - 20}px`;
    } else {
        const createdom = document.createElement(id);
        createdom.style.left = `${scenepPosition.x}px`;
        createdom.style.top = `${scenepPosition.y}px`;
        createdom.className = id;
        createdom.id = id;
        createdom.innerHTML = text;
        document.body.appendChild(createdom);
    }
};

export const removeMeasureElement = () => {
    const child = document.getElementsByTagName(id);
    let index = child.length - 1;
    for (index; index >= 0; index -= 1) {
        child[index].parentNode.removeChild(child[index]);
    }
};