Simple implementation of css+javascript of tree-like structure navigation bar
Source: Internet
Author: User
To do a can expand the folding tree navigation bar, to the Internet to see some implementation, feel more trouble, JS code is not small, my application requirements are not complex, but the requirements of the tree-like structure can be changed. So in the end, I tried to write one.
The following is the demo code, you can change the content of the div according to their own requirements, the dynamic generation of div part of the code can achieve the dynamic establishment of tree structure.
<script>
function changevisible (Element) {
var children = Element.parentNode.childNodes;
for (var i= 0; i<children.length;i++) {
if (Children[i].nodename = = "DIV") {
var className = Children[i].classname;
if (ClassName = = "Show") {
Element.classname= "fold";
Children[i].classname= "hidden";
}
else{
Element.classname= "Expend";
Children[i].classname= "Show";
}
}
}
}
</script>
<style type= "Text/css" >
div.show{
Display:block;
width:100%;
Background-color: #339966;
}
div.hidden{
Display:none;
}
The following is an effect demo:
+10 +20 +21 +22 30 31 (due to the expansion and collection of the icon used by the relative link to change the span of the classname properties to change the icon, in the blog is not convenient and practical, the use of + instead of the original chart position, you can use your own diagram Mark instead of M1.gif, P1.gif, d.gif, and your page in one-layer folder.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.