Javascript Twitter引导中的树

Javascript Twitter引导中的树,javascript,jquery,twitter-bootstrap,css,jquery-ui,Javascript,Jquery,Twitter Bootstrap,Css,Jquery Ui,我一直在尝试创建一个树(比如目录树),它使用尽可能多的CSS和尽可能少的JS(仅适用于州等),我想知道是否有一些好的现有树插件用于或 作为参考或对这个问题感到困惑的人,我正在寻找类似引导的东西 你能相信下图中的treeview不使用任何JavaScript,只依赖CSS3吗?查看此CSS3 TreeView,它对Twitter引导非常有用: 您可以在这里获得更多信息。对于那些仍在使用CSS3搜索树的人来说,这是我在网上找到的一段非常棒的代码: HTML PS:除了代码之外,我还喜欢网站在实

我一直在尝试创建一个树(比如目录树),它使用尽可能多的CSS和尽可能少的JS(仅适用于州等),我想知道是否有一些好的现有树插件用于或


作为参考或对这个问题感到困惑的人,我正在寻找类似引导的东西

你能相信下图中的treeview不使用任何JavaScript,只依赖CSS3吗?查看此CSS3 TreeView,它对Twitter引导非常有用:


您可以在这里获得更多信息。

对于那些仍在使用CSS3搜索树的人来说,这是我在网上找到的一段非常棒的代码:

HTML
PS:除了代码之外,我还喜欢网站在实际操作中显示的方式。。。非常创新。

另一个伟大的Treeview jquery插件是


对于高级视图,您应该检查jquery treetable

如果有人想从Harsh的答案中查看垂直版本的treeview,您可以节省一些时间:


如果有人想从Vitaliy Bychik的答案中获得可扩展/可折叠版本的treeview,您可以节省一些时间:)

在和的基础上,我将
a
标记更改为
span
标记,并将一些和合并到中

示例:

为了获得额外的积分,我创建了一个引导程序。请参阅项目文档,网址为

或者,这里是生成CSS的较少来源(JS可以从以下位置获取):



哇!这是一个好的。。。我得调查一下这个。。。谢谢…@当然,它的引导程序已经准备好,如果有帮助,请接受我的回答。:)附言:我们正在使用它。:)这个解决方案看起来不错,但是有一些我们想要的功能,但在这个版本中没有提供,例如分支突出显示等。但是无论如何,这是一个非常好的例子,说明了如何进行树样式。发现了一个很好的例子,值得注意的是,答案中提到的博客文章包含一些简单的CSS,这对我来说并不适用,但是实际的演示包含一些更复杂的(没有解释)CSS。这与您在问题中建议的树类型完全不同。我相信Praveen Kumar应该得到他的回答。我正在寻找一棵像第一棵树一样的树,看到了这个答案,决定用它来代替。有趣的是灵感是如何改变解决方案的@Blowsie:我已经考虑了你的建议,正义得到了伸张,lol。很高兴看到一个独立的项目因为某个随机的家伙的随机请求而不断发展。快速演示:根据网站的说法,它从2010年4月起就不再被支持了哦,很遗憾它没有被支持。。。看起来不错。嗨,这两个库都是最新的,并且都受支持。它们都受支持-请参阅“做得好”。当然,除了
.parent_li
的孩子们的奇怪行为,当他们的父母在你的第二棵树上悬停时,他们会失去背景色,变成灰色。谢谢@Harsh。您认为奇怪的悬停行为遵循Vitaliy的编程,为用户提供了一个可视化指示器,指示哪些节点将被折叠。@Jeromy French这棵树有一个非常好、平滑的体验。这正是我搜索时想要的。干得好,谢谢你的密码。你如何处理违约?当你访问页面时,我希望它被折叠?你能帮我吗?谢谢我更新了代码,在这里为Bootstrap3.0设计了一个新的提琴:简单而优雅。投赞成票:)这是完美的解决方案!哇,很好的解决方案-而且很容易扩展!折叠展开功能在哪里?:)很好!好主意+1.我添加了$('.tree>ul>li:first child').show();支持页面上的多棵树。谢谢
<div class="tree">
  <ul>
    <li>
      <a href="#">Parent</a>
      <ul>
        <li>
          <a href="#">Child</a>
          <ul>
            <li>
              <a href="#">Grand Child</a>
            </li>
          </ul>
        </li>
        <li>
          <a href="#">Child</a>
          <ul>
            <li><a href="#">Grand Child</a></li>
            <li>
              <a href="#">Grand Child</a>
              <ul>
                <li>
                  <a href="#">Great Grand Child</a>
                </li>
                <li>
                  <a href="#">Great Grand Child</a>
                </li>
                <li>
                  <a href="#">Great Grand Child</a>
                </li>
              </ul>
            </li>
            <li><a href="#">Grand Child</a></li>
          </ul>
        </li>
      </ul>
    </li>
  </ul>
</div>
* {margin: 0; padding: 0;}

.tree ul {
  padding-top: 20px; position: relative;

  transition: all 0.5s;
  -webkit-transition: all 0.5s;
  -moz-transition: all 0.5s;
}

.tree li {
  float: left; text-align: center;
  list-style-type: none;
  position: relative;
  padding: 20px 5px 0 5px;

  transition: all 0.5s;
  -webkit-transition: all 0.5s;
  -moz-transition: all 0.5s;
}

/*We will use ::before and ::after to draw the connectors*/

.tree li::before, .tree li::after{
  content: '';
  position: absolute; top: 0; right: 50%;
  border-top: 1px solid #ccc;
  width: 50%; height: 20px;
}
.tree li::after{
  right: auto; left: 50%;
  border-left: 1px solid #ccc;
}

/*We need to remove left-right connectors from elements without 
any siblings*/
.tree li:only-child::after, .tree li:only-child::before {
  display: none;
}

/*Remove space from the top of single children*/
.tree li:only-child{ padding-top: 0;}

/*Remove left connector from first child and 
right connector from last child*/
.tree li:first-child::before, .tree li:last-child::after{
  border: 0 none;
}
/*Adding back the vertical connector to the last nodes*/
.tree li:last-child::before{
  border-right: 1px solid #ccc;
  border-radius: 0 5px 0 0;
  -webkit-border-radius: 0 5px 0 0;
  -moz-border-radius: 0 5px 0 0;
}
.tree li:first-child::after{
  border-radius: 5px 0 0 0;
  -webkit-border-radius: 5px 0 0 0;
  -moz-border-radius: 5px 0 0 0;
}

/*Time to add downward connectors from parents*/
.tree ul ul::before{
  content: '';
  position: absolute; top: 0; left: 50%;
  border-left: 1px solid #ccc;
  width: 0; height: 20px;
}

.tree li a{
  border: 1px solid #ccc;
  padding: 5px 10px;
  text-decoration: none;
  color: #666;
  font-family: arial, verdana, tahoma;
  font-size: 11px;
  display: inline-block;

  border-radius: 5px;
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;

  transition: all 0.5s;
  -webkit-transition: all 0.5s;
  -moz-transition: all 0.5s;
}

/*Time for some hover effects*/
/*We will apply the hover effect the the lineage of the element also*/
.tree li a:hover, .tree li a:hover+ul li a {
  background: #c8e4f8; color: #000; border: 1px solid #94a0b4;
}
/*Connector styles on hover*/
.tree li a:hover+ul li::after, 
.tree li a:hover+ul li::before, 
.tree li a:hover+ul::before, 
.tree li a:hover+ul ul::before{
  border-color:  #94a0b4;
}
.tree li {
    margin: 0px 0;

    list-style-type: none;
    position: relative;
    padding: 20px 5px 0px 5px;
}

.tree li::before{
    content: '';
    position: absolute; 
    top: 0;
    width: 1px; 
    height: 100%;
    right: auto; 
    left: -20px;
    border-left: 1px solid #ccc;
    bottom: 50px;
}
.tree li::after{
    content: '';
    position: absolute; 
    top: 30px; 
    width: 25px; 
    height: 20px;
    right: auto; 
    left: -20px;
    border-top: 1px solid #ccc;
}
.tree li a{
    display: inline-block;
    border: 1px solid #ccc;
    padding: 5px 10px;
    text-decoration: none;
    color: #666;
    font-family: arial, verdana, tahoma;
    font-size: 11px;
    border-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
}

/*Remove connectors before root*/
.tree > ul > li::before, .tree > ul > li::after{
    border: 0;
}
/*Remove connectors after last child*/
.tree li:last-child::before{ 
      height: 30px;
}

/*Time for some hover effects*/
/*We will apply the hover effect the the lineage of the element also*/
.tree li a:hover, .tree li a:hover+ul li a {
    background: #c8e4f8; color: #000; border: 1px solid #94a0b4;
}
/*Connector styles on hover*/
.tree li a:hover+ul li::after, 
.tree li a:hover+ul li::before, 
.tree li a:hover+ul::before, 
.tree li a:hover+ul ul::before{
    border-color:  #94a0b4;
}
$(function () {
    $('.tree li').hide();
    $('.tree li:first').show();
    $('.tree li').on('click', function (e) {
        var children = $(this).find('> ul > li');
        if (children.is(":visible")) children.hide('fast');
        else children.show('fast');
        e.stopPropagation();
    });
});
@import "../../../external/bootstrap/less/bootstrap.less"; /* substitute your path to the bootstrap.less file */
@import "../../../external/bootstrap/less/responsive.less"; /* optional; substitute your path to the responsive.less file */

/* collapsable tree */
.tree {
    .border-radius(@baseBorderRadius);
    .box-shadow(inset 0 1px 1px rgba(0,0,0,.05));
    background-color: lighten(@grayLighter, 5%);
    border: 1px solid @grayLight;
    margin-bottom: 10px;
    max-height: 300px;
    min-height: 20px;
    overflow-y: auto;
    padding: 19px;
    a {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        width: 90%;
    }
    li {
        list-style-type: none;
        margin: 0px 0;
        padding: 4px 0px 0px 2px;
        position: relative;
        &::before, &::after {
            content: '';
            left: -20px;
            position: absolute;
            right: auto;
        }
        &::before {
            border-left: 1px solid @grayLight;
            bottom: 50px;
            height: 100%;
            top: 0;
            width: 1px;
        }
        &::after {
            border-top: 1px solid @grayLight;
            height: 20px;
            top: 13px;
            width: 23px;
        }
        span {
            -moz-border-radius: 5px;
            -webkit-border-radius: 5px;
            border: 1px solid @grayLight;
            border-radius: 5px;
            display: inline-block;
            line-height: 14px;
            padding: 2px 4px;
            text-decoration: none;
        }
        &.parent_li > span {
            cursor: pointer;
            /*Time for some hover effects*/
            &:hover, &:hover+ul li span {
                background: @grayLighter;
                border: 1px solid @gray;
                color: #000;
            }
        }
        /*Remove connectors after last child*/
        &:last-child::before {
            height: 30px;
        }
    }
    /*Remove connectors before root*/
    > ul > li::before, > ul > li::after {
        border: 0;
    }
}