文章内容
SimpleTree是一款小巧,功能强大,能拖拽,支持异步,且兼容性很高的jquery Tree插件, 使用SimpleTree可以轻松制作一个树形菜单效果,在这里我介绍一个我工作种经常用到的一个效果。
html代码
<link rel="stylesheet" href="css/index.css" />
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/simpletree.js"></script>
<div class="main clearfix">
<li class=" on "><a>一级类别</a></li>
<li class=""><a href="#">二级类别</a></li>
<li class=" "><a>一级类别</a></li>
<li class=" active "><a href="#">二级类别</a></li>
<li class=""><a>一级类别</a></li>
<li class=""><a href="#">二级类别</a></li>
<li class=""><a href="#">二级类别</a></li>
<li class=""><a>二级类别</a></li>
<li class=""><a href="#">三级类别</a></li>
<li class=""><a href="#">三级类别</a></li>
<li class=""><a href="#">三级类别</a></li>
$(".st_tree").SimpleTree({
if (!$(a).attr("hasChild"))
<link rel="stylesheet" href="css/index.css" />
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/simpletree.js"></script>
<div class="main clearfix">
<div class="main-l">
<div class="mainl-fl">
<h3>
产品类别</h3>
<div class="st_tree">
<ul>
<li class=" on "><a>一级类别</a></li>
<ul>
<li class=""><a href="#">二级类别</a></li>
</ul>
<li class=" "><a>一级类别</a></li>
<ul>
<li class=" active "><a href="#">二级类别</a></li>
</ul>
<li class=""><a>一级类别</a></li>
<ul>
<li class=""><a href="#">二级类别</a></li>
<li class=""><a href="#">二级类别</a></li>
<li class=""><a>二级类别</a></li>
<ul>
<li class=""><a href="#">三级类别</a></li>
<li class=""><a href="#">三级类别</a></li>
<li class=""><a href="#">三级类别</a></li>
</ul>
</ul>
</ul>
</div>
</div>
</div>
</div>
<script>
$(function () {
$(".st_tree").SimpleTree({
click: function (a) {
if (!$(a).attr("hasChild"))
alert($(a).attr("ref"));
}
});
});
</script>
<link rel="stylesheet" href="css/index.css" />
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/simpletree.js"></script>
<div class="main clearfix">
<div class="main-l">
<div class="mainl-fl">
<h3>
产品类别</h3>
<div class="st_tree">
<ul>
<li class=" on "><a>一级类别</a></li>
<ul>
<li class=""><a href="#">二级类别</a></li>
</ul>
<li class=" "><a>一级类别</a></li>
<ul>
<li class=" active "><a href="#">二级类别</a></li>
</ul>
<li class=""><a>一级类别</a></li>
<ul>
<li class=""><a href="#">二级类别</a></li>
<li class=""><a href="#">二级类别</a></li>
<li class=""><a>二级类别</a></li>
<ul>
<li class=""><a href="#">三级类别</a></li>
<li class=""><a href="#">三级类别</a></li>
<li class=""><a href="#">三级类别</a></li>
</ul>
</ul>
</ul>
</div>
</div>
</div>
</div>
<script>
$(function () {
$(".st_tree").SimpleTree({
click: function (a) {
if (!$(a).attr("hasChild"))
alert($(a).attr("ref"));
}
});
});
</script>
index.css代码
-mos-transition: all 0.3s;
-webkit-transition: all 0.3s;
.clearfix:before, .clearfix:after
border-bottom: 1px solid #e5e5e5;
border-bottom: 1px solid #e5e5e5;
.st_tree ul ul li.active a
.st_tree ul ul li:hover a
background: url(../images/st_jt.png) no-repeat left 10px center;
.st_tree .open, .st_tree .on
background: #ededed url(../images/st_jt.png) no-repeat left 10px center;
background: #ededed url(../images/st_jt_open.png) no-repeat left 10px center;
.st_tree .open a, .st_tree .on a
<style>
*
{
margin: 0;
padding: 0;
list-style: none;
font-family: "微软雅黑";
box-sizing: border-box;
}
body
{
overflow-x: hidden;
}
img
{
border: 0;
}
a
{
text-decoration: none;
color: #333;
transition: all 0.3s;
-o-transition: all 0.3s;
-mos-transition: all 0.3s;
-webkit-transition: all 0.3s;
}
input, textarea, button
{
outline: none;
}
em
{
font-style: normal;
}
h1, h2, h3, h4, h5, h6
{
font-weight: normal;
}
.clearfix
{
zoom: 1;
clear: none;
}
.clearfix:before, .clearfix:after
{
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.mainl-fl > h3
{
width: 250px;
margin-left: -1px;
height: 66px;
line-height: 66px;
text-align: center;
font-size: 21px;
font-weight: bold;
background: #83c1f7;
color: #fff;
}
.main-l
{
width: 250px;
border-top: none;
}
.st_tree
{
width: 100%;
height: auto;
overflow: hidden;
}
.st_tree a
{
text-decoration: none;
}
.st_tree a:hover
{
color: #20649f;
}
.st_tree ul
{
width: 100%;
height: auto;
overflow: hidden;
}
.st_tree > ul > ul
{
padding-left: 20px;
}
.st_tree > ul > ul > ul
{
padding-left: 20px;
}
.st_tree ul li
{
color: #393939;
font-size: 16px;
float: left;
line-height: 52px;
width: 100%;
height: 52px;
border-bottom: 1px solid #e5e5e5;
}
.st_tree ul ul li
{
padding-left: 10px;
}
.st_tree ul li ul
{
width: 100%;
height: auto;
overflow: hidden;
}
.st_tree ul li ul li
{
width: 100%;
height: auto;
overflow: hidden;
line-height: 35px;
padding-left: 10px;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
border-bottom: 1px solid #e5e5e5;
}
.st_tree ul li ul li a
{
color: #393939;
font-size: 14px;
width: 100%;
height: 100%;
display: block;
}
.st_tree ul ul li a
{
color: #393939;
font-size: 14px;
width: 100%;
height: 100%;
display: block;
}
.st_tree ul ul li.active a
{
color: #20649f;
}
.st_tree ul ul li:hover a
{
color: #20649f;
}
.st_tree .folder
{
background: url(../images/st_jt.png) no-repeat left 10px center;
padding: 0 10px 0 30px;
}
.st_tree .open, .st_tree .on
{
background: #ededed url(../images/st_jt.png) no-repeat left 10px center;
padding: 0 10px 0 30px;
}
.st_tree .open
{
background: #ededed url(../images/st_jt_open.png) no-repeat left 10px center;
padding: 0 10px 0 30px;
}
.st_tree .open a, .st_tree .on a
{
color: #20649f;
}
</style>
<style>
*
{
margin: 0;
padding: 0;
list-style: none;
font-family: "微软雅黑";
box-sizing: border-box;
}
body
{
overflow-x: hidden;
}
img
{
border: 0;
}
a
{
text-decoration: none;
color: #333;
transition: all 0.3s;
-o-transition: all 0.3s;
-mos-transition: all 0.3s;
-webkit-transition: all 0.3s;
}
input, textarea, button
{
outline: none;
}
em
{
font-style: normal;
}
h1, h2, h3, h4, h5, h6
{
font-weight: normal;
}
.clearfix
{
zoom: 1;
clear: none;
}
.clearfix:before, .clearfix:after
{
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.mainl-fl > h3
{
width: 250px;
margin-left: -1px;
height: 66px;
line-height: 66px;
text-align: center;
font-size: 21px;
font-weight: bold;
background: #83c1f7;
color: #fff;
}
.main-l
{
width: 250px;
border-top: none;
}
.st_tree
{
width: 100%;
height: auto;
overflow: hidden;
}
.st_tree a
{
text-decoration: none;
}
.st_tree a:hover
{
color: #20649f;
}
.st_tree ul
{
width: 100%;
height: auto;
overflow: hidden;
}
.st_tree > ul > ul
{
padding-left: 20px;
}
.st_tree > ul > ul > ul
{
padding-left: 20px;
}
.st_tree ul li
{
color: #393939;
font-size: 16px;
float: left;
line-height: 52px;
width: 100%;
height: 52px;
border-bottom: 1px solid #e5e5e5;
}
.st_tree ul ul li
{
padding-left: 10px;
}
.st_tree ul li ul
{
width: 100%;
height: auto;
overflow: hidden;
}
.st_tree ul li ul li
{
width: 100%;
height: auto;
overflow: hidden;
line-height: 35px;
padding-left: 10px;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
border-bottom: 1px solid #e5e5e5;
}
.st_tree ul li ul li a
{
color: #393939;
font-size: 14px;
width: 100%;
height: 100%;
display: block;
}
.st_tree ul ul li a
{
color: #393939;
font-size: 14px;
width: 100%;
height: 100%;
display: block;
}
.st_tree ul ul li.active a
{
color: #20649f;
}
.st_tree ul ul li:hover a
{
color: #20649f;
}
.st_tree .folder
{
background: url(../images/st_jt.png) no-repeat left 10px center;
padding: 0 10px 0 30px;
}
.st_tree .open, .st_tree .on
{
background: #ededed url(../images/st_jt.png) no-repeat left 10px center;
padding: 0 10px 0 30px;
}
.st_tree .open
{
background: #ededed url(../images/st_jt_open.png) no-repeat left 10px center;
padding: 0 10px 0 30px;
}
.st_tree .open a, .st_tree .on a
{
color: #20649f;
}
</style>
在线演示:演示