Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

line position issue in collapse div #385

Closed
zakk616 opened this issue Dec 30, 2022 · 3 comments
Closed

line position issue in collapse div #385

zakk616 opened this issue Dec 30, 2022 · 3 comments

Comments

@zakk616
Copy link

zakk616 commented Dec 30, 2022

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
Copy link
Owner

anseki commented Dec 30, 2022

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
Copy link
Author

zakk616 commented Dec 30, 2022

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()

@zakk616 zakk616 closed this as completed Dec 30, 2022
@anseki
Copy link
Owner

anseki commented Dec 30, 2022

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. 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants