简体   繁体   English

使用CSS的Galaxy类结构

[英]Galaxy like Structure using CSS

I want to build a node connector application using JSPlumb. 我想使用JSPlumb构建节点连接器应用程序。

Now the idea is that there would be central div element which can connect to all the 现在的想法是,将有一个中央div元素可以连接到所有

div element distributed along the circumference of the of central div at a specific radius div元素沿中心div的圆周以特定半径分布 在此处输入图片说明

Attaching the screenshot for the same is this possible to do with CSS plainly 附上相同的屏幕截图可以用CSS轻松完成

Sorry if my question confusion anybody but I decide by explain it as efficiently as I could.I would highly appreciate it some one editing this for better understanding perspective 对不起,如果我的问题让任何人困惑,但我决定通过尽可能有效地解释它,我将不胜感激有人为了更好地理解观点而对此进行了编辑

Regards 问候

Mess around with this. 乱七八糟的。

http://jsfiddle.net/A7pY2/2/ http://jsfiddle.net/A7pY2/2/

HTML: HTML:

<div id="container">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
</div>

CSS: CSS:

#container {
     position: absolute;
    top: 300px;
    left: 300px;
}
#container div {
    position: absolute;
    background-color: #eee;
    width: 50px;
    height: 50px;
}

JavaScript: JavaScript:

startCar();

function startCar() {
    var items = document.getElementById("container").getElementsByTagName("div").length;
    var angles = new Array(items);
    var rx = 200;
    var ry = 100;

    initCar();



    function initCar() {
        var content = document.getElementById("container");
        var divs = content.getElementsByTagName("div");
        var xpos, ypos;
        for(var i = 0; i < items; i++) {
            angles[i] = ((Math.PI * 2) / items) * i;
            xpos = Math.cos(angles[i]) * rx;
            ypos = Math.sin(angles[i]) * ry;
            divs[i].style.left = xpos + 'px';
            divs[i].style.top = ypos + 'px';
            divs[i].style.zIndex = parseInt(ypos);
        }
    }

}

Well, I'm not going to learn JSPlumb, but I can tell you how I'd solve the HTML/CSS side of it with some pointers on how to use that layout to your advantage in the JS. 好吧,我不会学习JSPlumb,但是我可以通过一些关于如何在JS中利用该布局的优势的指针,告诉您如何解决HTML / CSS方面的问题。 I don't think there would be any practical non-convoluted/silly way to set coordinates with CSS-only since there is math required here but you might be able to do it with SVG which is what JSPlumb appears to be using on its demo page. 我不认为会有任何实用的非卷积/愚蠢的方法来仅使用CSS来设置坐标,因为这里需要数学运算,但是您可能可以使用SVG来实现,这就是JSPlumb似乎在其演示中使用的页。

CSS: CSS:

#central_div { position:relative; overflow:visible; }
/* or absolute or fixed */

.orbit { overflow:visible; }
/* no position set for orbits so stars anchor to #central_div */

.star { position:absolute; width:20px; height:20px; }

HTML: HTML:

<div id="central_div">

    <div class="orbit" data-radius="50">
        <div class="star" data-radians="1.23"></div>
        <div class="star" data-radians="2.22"></div>
        <div class="star" data-radians="4.10"></div>
        <div class="star" data-radians="6.01"></div>
    </div>

    <div class="orbit" data-radius="100">
        <div class="star" data-radians="1.23"></div>
        <div class="star" data-radians="2.22"></div>
        <div class="star" data-radians="4.10"></div>
        <div class="star" data-radians="6.01"></div>
    </div>

</div>

Note: Keep in mind the orbit divs all sit in side the central div. 注意:请记住,所有轨道div都位于中央div旁边。 They're just there to organize your stars and provide an easily adjusted orbit hook in the form of a data-radius attribute. 它们只是用来组织您的恒星,并以数据半径属性的形式提供易于调整的轨道钩。 There is no need to set any dimensions on them or move them around. 无需在其上设置任何尺寸或移动它们。

JS: JS:

Now your JS can loop through the orbits, take the data-radius and apply that to the star radian or degree data (can convert to one or the other easily). 现在,您的JS可以遍历轨道,获取数据半径,并将其应用于星弧度或度数数据(可以轻松转换为一个或另一个)。 I'll leave the geometry to you for now since this seems more like a markup/css question but let's assume a function called setStarCoordinates that takes <star dom element object> , <radius> , and <radians or degrees - your choice> for arguments. 我现在将几何留给您,因为这似乎更像是一个标记/ css问题,但是让我们假设一个名为setStarCoordinates的函数,该函数采用<star dom element object><radius><radians or degrees - your choice> setStarCoordinates <radians or degrees - your choice>作为论点。

Only the stars have height/width dimensions but they themselves are absolute so their containers can all be assumed to occupy a single x,y point. 只有星星具有高度/宽度尺寸,但是它们本身是绝对的,因此可以假定它们的容器都占据单个x,y点。 Aside from the geometry you have to set top and left coordinates of the stars as top + (.5 * height) and left as left + (.5 * width) 除了几何图形,还必须将星星的顶部和左侧坐标设置为top + (.5 * height) ,将左侧设置为left + (.5 * width)

Link on radians: http://www.teacherschoice.com.au/maths_library/angles/angles.htm 弧度上的链接: http : //www.teacherschoice.com.au/maths_library/angles/angles.htm

And then a loop that's something like this: 然后是一个像这样的循环:

var orbits = document.querySelectorAll('#central_div .orbit'),
i = orbits.length;

while(i--){
    var radius = orbits[i].getAttribute('data-radius'),
    stars = orbits.getElementsByClassName('star'),
    //or use querySelectorAll again if you're supporting IE8
    j = stars.length;

    while(j--){
        var thisStar = stars[j],
        radian == thisStar.getAttribute('data-radian');
        setStarCoords(thisStar, radius, radian);
    }
}

The simplest way to do this would be to have a DIV with a background image of the dotted lines. 最简单的方法是使用带有虚线背景图像的DIV。

Then have more DIVs, A tags or whatever absolutely positioned on top of this. 然后有更多的DIV,A标签或绝对位于其上的任何内容。

<div id="my-background-div">
    <a href="#">Node #1</a>
    <a href="#">Node #2</a>
    <a href="#">Node #3</a>
    <a href="#">Node #4</a>
</div>

...and so on. ...等等。

Not a programmatic solution but I don't think that would be possible with just plain CSS so my solution above would be fine for a static page. 这不是一个编程解决方案,但我认为仅凭普通CSS不可能实现,因此上述解决方案对于静态页面来说是可以的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM