0

Here you can find my whole code: http://jsfiddle.net/dpbbd/

Everything is working fine, but there is something that tickle me and its this:

    function drawLine()
    {
        var div1 = document.getElementById('circle');
        var div2 = document.getElementById('companyName');
        connect(div1, div2, "#000", 1, "line1");
        var div1 = document.getElementById('circle2');
        var div2 = document.getElementById('companyName');
        connect(div1, div2, "#000", 1, "line2");
        var div1 = document.getElementById('circle3');
        var div2 = document.getElementById('companyName');
        connect(div1, div2, "#000", 1, "line3");
        $('.line1').fadeIn(800, function() {
        });
        $('.line2').fadeIn(800, function() {
        });
        $('.line3').fadeIn(800, function() {
        });
    }

You see im declaring var div1 div2 over and over even if its the same damn thing... Now i tryed this:

function drawLine()
{
    var div1 = document.getElementById('circle');
    var div2 = document.getElementById('companyName');
    connect(div1, div2, "#000", 1, "line1");
    var div3 = document.getElementById('circle2');
     connect(div3, div2, "#000", 1, "line2");
    var div4 = document.getElementById('circle3');
    connect(div4, div2, "#000", 1, "line3");
    $('.line1').fadeIn(800, function() {
    });
    $('.line2').fadeIn(800, function() {
    });
    $('.line3').fadeIn(800, function() {
    });
}

The error that give me is the line start drawing from the circle as normal, then go right at 0 like if div2 never existed... The first circle is working fine and the line connect to the text in the middle cause the variable is declared right before it. But as soon as i remove the var div2 before other connect, not working anymore.

Could someone explain to me whats happening o_O

4

1 回答 1

2

当您更改 document.body 的 innerhtml 时,所有对象都会重新创建。这就是为什么你必须一直重新获取元素的原因。

如果您不想这样做,则需要附加到正文而不是一直更改其 html。

于 2013-04-17T11:46:19.047 回答