html+css3+jquery多级目录树型结构菜单

时间:2024-10-11 19:15:00

1、准备好需要用到的图标。

html+css3+jquery多级目录树型结构菜单
html+css3+jquery多级目录树型结构菜单
html+css3+jquery多级目录树型结构菜单
html+css3+jquery多级目录树型结构菜单
html+css3+jquery多级目录树型结构菜单
html+css3+jquery多级目录树型结构菜单
html+css3+jquery多级目录树型结构菜单
html+css3+jquery多级目录树型结构菜单
html+css3+jquery多级目录树型结构菜单
html+css3+jquery多级目录树型结构菜单
html+css3+jquery多级目录树型结构菜单
html+css3+jquery多级目录树型结构菜单

2、新建html文档。

html+css3+jquery多级目录树型结构菜单

3、书写hmtl代码。<div class="htmleaf-container"> <div class="htmleaf-content"> <h2>带日志JS多级目录树结构特效</h2> <button onClick="expand_all()">扩大所有节点</button> <button onClick="collapse_all()">所有节点崩溃</button> <button onClick="clear_log()">清除日志</button> <br/><br/> <div id="div_log"></div> <div id="div_tree"></div> </div></div>

html+css3+jquery多级目录树型结构菜单

4、书写css代码。body { font-family: 'Helvetica Neue'稆糨孝汶;, Helvetica, 'Segoe UI', Arial, freesans; }#div_tree { font: 10px Verdana, sans-serif; display: inline-block; width: 300px; }#div_log { width: 400px; height: 400px; overflow: scroll; padding: 10px; vertical-align: top; display: inline-block; border: 1px solid gray; font: 10px Verdana, sans-serif; line-height: 16px; }ul.tree, ul.tree ul { list-style-type: none; background: url(vline.png) repeat-y; margin: 0; padding: 0; padding-left: 7px; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; cursor: default; }li.last { background-image: 'url("css/lastnode.png")'; background-repeat: no-repeat; }ul.tree ul { padding-left: 7px; }ul.tree li { margin: 0; padding: 0 12px; line-height: 22px; background: url(node.png) no-repeat; }ul.tree li.last { background: #fff url(lastnode.png) no-repeat; }img.exp_col { position: absolute; margin-top: 4px; margin-left: -20px; vertical-align: sub; }img.exp_col_empty { position: absolute; margin-top: 4px; margin-left: -20px; vertical-align: sub; width: 16px; }img.icon_tree { vertical-align: middle; padding-left: 3px; margin-top: -3px; }a.node { padding: 2px; }span.node a { padding-left: 3px; }span.node { margin-left: -1px; padding-right: 3px; padding-top: 4px; padding-bottom: 4px; }span.node:hover { margin-left: -1px; padding-right: 3px; padding-top: 4px; padding-bottom: 4px; background-color: #DCEDFF; border-radius: 2px; }span.node_selected { margin-left: -2px; padding-right: 3px; padding-top: 4px; padding-bottom: 4px; background-color: #CEFFCE; border: 1px solid #8AE88A; border-radius: 2px; }span.node_selected a { padding-left: 3px; }.menu, .sub-menu { margin: 0; padding: 0; font: 10px Verdana, sans-serif; }.menu, .sub-menu { list-style: none; background: #000; }.sub-menu { background: #F1F1F1; }.menu a { text-decoration: none; display: inline-block; padding: 8px; }.menu span { position: absolute; width: 100%; height: 100%; }.menu div { position: absolute; right: 4px; top: 0px; padding: 8px; }.menu .menu_img { vertical-align: middle; }.menu img { text-decoration: none; display: inline-block; vertical-align: sub; padding-left: 5px; }.menu li { position: relative; }.menu li:hover { background: aquamarine; cursor: pointer; }.sub-menu li:hover { background: aquamarine; }.menu li:hover > .sub-menu { display: block; }.menu { width: 150px; position: absolute; background: #F1F1F1; -webkit-user-select: none; /* Chrome/Safari */ -moz-user-select: none; /* Firefox */ -ms-user-select: none; /* IE10+ */ cursor: default; box-shadow: 2px 2px 3px #BDBDBD; }.sub-menu { display: none; position: absolute; min-width: 150px; box-shadow: 2px 2px 3px #BDBDBD; }.menu .sub-menu { top: 0; left: 100%; }

html+css3+jquery多级目录树型结构菜单

5、书写并添加js蜣贺鱿柢代码。<script src="lib/Aimara.js"></script><script> win dow.onload = function() { var contex_menu = { 'context1' : { elements : [ { text : 'Node Actions', icon: 'images/blue_key.png', action : function(node) { }, submenu: { elements : [ { text : 'Toggle Node', icon: 'images/leaf.png', action : function(node) { node.toggleNode(); } }, { text : 'Expand Node', icon: 'images/leaf.png', action : function(node) { node.expandNode(); } }, { text : 'Collapse Node', icon: 'images/leaf.png', action : function(node) { node.collapseNode(); } }, { text : 'Expand Subtree', icon: 'images/tree.png', action : function(node) { node.expandSubtree(); } }, { text : 'Collapse Subtree', icon: 'images/tree.png', action : function(node) { node.collapseSubtree(); } }, { text : 'Delete Node', icon: 'images/delete.png', action : function(node) { node.removeNode(); } }, ] } }, { text : 'Child Actions', icon: 'images/blue_key.png', action : function(node) { }, submenu: { elements : [ { text : 'Create Child Node', icon: 'images/add1.png', action : function(node) { node.createChildNode('Created',false,'images/folder.png',null,'context1'); } }, { text : 'Create 1000 Child Nodes', icon: 'images/add1.png', action : function(node) { for (var i=0; i<1000; i++) node.createChildNode('Created -' + i,false,'images/folder.png',null,'context1'); } }, { text : 'Delete Child Nodes', icon: 'images/delete.png', action : function(node) { node.removeChildNodes(); } } ] } } ] } }; tree = createTree('div_tree','white',contex_menu); div_log = document.getElementById('div_log'); tree.nodeBeforeOpenEvent = function(node) { div_log.innerHTML += node.text + ': Before expand event<br/>'; } tree.nodeAfterOpenEvent = function(node) { div_log.innerHTML += node.text + ': After expand event<br/>'; } tree.nodeBeforeCloseEvent = function(node) { div_log.innerHTML += node.text + ': Before collapse event<br/>'; } for (var i=1; i<10; i++) { node1 = tree.createNode('Level 0 - Node ' + i,false,'images/star.png',null,null,'context1'); for (var j=1; j<5; j++) { node2 = node1.createChildNode('Level 1 - Node ' + j, false, 'images/blue_key.png',null,'context1'); for (var k=1; k<5; k++) { node3 = node2.createChildNode('Level 2 - Node ' + k, false, 'images/monitor.png',null,'context1'); } } } tree.drawTree(); tree.createNode('Real Time',false,'images/leaf.png',null,null,'context1'); }; function expand_all() { tree.expandTree(); } function clear_log() { document.getElementById('div_log').innerHTML = ''; } function collapse_all() { tree.collapseTree(); }</script>

html+css3+jquery多级目录树型结构菜单

6、代码整体结构。

html+css3+jquery多级目录树型结构菜单

7、查看效果。

html+css3+jquery多级目录树型结构菜单
© 手抄报圈