anseki / leader-line

Draw a leader line in your web page.
http://anseki.github.io/leader-line/
MIT License
3.03k stars 423 forks source link

line position issue in collapse div #385

Closed zakk616 closed 1 year ago

zakk616 commented 1 year ago

the lines don't work currect in a collapsing div.

https://jsfiddle.net/zakk616/mtj2hpb7/11/

is there any solution when the collapse changes the lines should re-render?

Some Screenshots: when collapse is open image

when collapse is closed image

anseki commented 1 year ago

Hi @zakk616, thank you for the comment. You can use position method for that. However, it seems that you don't need that, you only want to hide the lines maybe.

zakk616 commented 1 year ago

I implemented this solution:

var lines = [];
function drawLines(length) {
        for (let i = 1; i < length; i++) {
            var start = document.getElementById('history-card-' + i);
            var end = document.getElementById('history-card-' + (i + 1));

            lines.push(new LeaderLine(start, end, {
                color: '#00b97d', size: 2, path: 'grid',
                startSocket: 'right',
                endSocket: 'left',
            }));
        }
    }

    function showHide() {
        if (lines.length > 0) {
            lines.forEach(line => {
                line.remove();
                lines = [];
            });
        }
        else {
            setTimeout(() => {
                drawLines(data.length);
            }, 100);
        }
    }

now on collapse i call showHide()

anseki commented 1 year ago

That is not good code because that removes lines wastefully instead of hiding lines, and also that clears lines repeatedly that is not required. Good luck. :thumbsup: