js实现无限级下拉菜单弹出特效

2周前 (04-19 18:02)阅读21回复0
大陆
大陆
  • 管理员
  • 发消息
  • 注册排名1
  • 经验值4014
  • 级别管理员
  • 主题802
  • 回复2
楼主

js制作无限级折叠下拉菜单鼠标点击弹出显示特效,用户的鼠标点击按钮弹出下级菜单,可根据自己的需求来修改。

<title>js实现无限级下拉菜单弹出特效_武鸣人</title>
<style type="text/css"> 
*{ margin:0; padding:0;list-style:none;} 
body { margin:20px;}
h5 { font-size:12px; text-align:center; font-weight:normal; color:#666; line-height:28px;} 
#nav a { text-decoration:underline;color:#06c; font-size:14px; line-height:24px;} 
#nav ul{ margin-bottom:5px;} 
#nav strong{ color:#696;} 
#nav.dyn li ul{ display:none;} 
#nav.dyn li ul.show{ display:block;} 
#nav.dyn li{ padding-left:15px;} 
#nav.dyn li.parent{background:url(/img/20240419_www_wuming_ren_32.gif) 5px 10px no-repeat;} 
#nav.dyn li.open{ background:url(/img/20240419_www_wuming_ren_32.gif) 5px -34px no-repeat;} 
</style> 
<script type="text/javascript">
DOMhelp = {
debugWindowId: 'DOMhelpdebug',
init: function() {
if (!document.getElementById || !document.createTextNode) { return; }
},
lastSibling: function(node) {
var tempObj = node.parentNode.lastChild;
while (tempObj.nodeType != 1 && tempObj.previousSibling != null) {
tempObj = tempObj.previousSibling;
}//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
return (tempObj.nodeType == 1) ? tempObj : false;
},
firstSibling: function(node) {
var tempObj = node.parentNode.firstChild;
while (tempObj.nodeType != 1 && tempObj.nextSibling != null) {
tempObj = tempObj.nextSibling;
}//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
return (tempObj.nodeType == 1) ? tempObj : false;
},
getText: function(node) {
if (!node.hasChildNodes()) { return false; }
var reg = /^\s+$/;
var tempObj = node.firstChild;
while (tempObj.nodeType != 3 && tempObj.nextSibling != null || reg.test(tempObj.nodeValue)) {
tempObj = tempObj.nextSibling;
}
return tempObj.nodeType == 3 ? tempObj.nodeValue : false;
},
setText: function(node, txt) {
if (!node.hasChildNodes()) { return false; }
var reg = /^\s+$/;
var tempObj = node.firstChild;
while (tempObj.nodeType != 3 && tempObj.nextSibling != null || reg.test(tempObj.nodeValue)) {
tempObj = tempObj.nextSibling;
}//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
if (tempObj.nodeType == 3) { tempObj.nodeValue = txt } else { return false; }
},
createLink: function(to, txt) {
var tempObj = document.createElement('a');
tempObj.appendChild(document.createTextNode(txt));
tempObj.setAttribute('href', to);
return tempObj;
},
createTextElm: function(elm, txt) {
var tempObj = document.createElement(elm);
tempObj.appendChild(document.createTextNode(txt));
return tempObj;
},
closestSibling: function(node, direction) {
var tempObj;
if (direction == -1 && node.previousSibling != null) {
tempObj = node.previousSibling;
while (tempObj.nodeType != 1 && tempObj.previousSibling != null) {
tempObj = tempObj.previousSibling;
}//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
} else if (direction == 1 && node.nextSibling != null) {
tempObj = node.nextSibling;
while (tempObj.nodeType != 1 && tempObj.nextSibling != null) {
tempObj = tempObj.nextSibling;
}
}
return tempObj.nodeType == 1 ? tempObj : false;
},
initDebug: function() {
if (DOMhelp.debug) { DOMhelp.stopDebug(); }
DOMhelp.debug = document.createElement('div');
DOMhelp.debug.setAttribute('id', DOMhelp.debugWindowId);
document.body.insertBefore(DOMhelp.debug, document.body.firstChild);
},
setDebug: function(bug) {
if (!DOMhelp.debug) { DOMhelp.initDebug(); }
DOMhelp.debug.innerHTML += bug + '\n';
},
stopDebug: function() {
if (DOMhelp.debug) {
DOMhelp.debug.parentNode.removeChild(DOMhelp.debug);
DOMhelp.debug = null;
}//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
},
getKey: function(e) {
if (window.event) {
var key = window.event.keyCode;
} else if (e) {
var key = e.keyCode;
}//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
return key;
},
/* helper methods */
getTarget: function(e) {
var target = window.event ? window.event.srcElement : e ? e.target : null;
if (!target) { return false; }
while (target.nodeType != 1 && target.nodeName.toLowerCase() != 'body') {
target = target.parentNode;
}
return target;
},
stopBubble: function(e) {
if (window.event && window.event.cancelBubble) {
window.event.cancelBubble = true;
}//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
if (e && e.stopPropagation) {
e.stopPropagation();
}
},
stopDefault: function(e) {
if (window.event && window.event.returnValue) {
window.event.returnValue = false;
}//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
if (e && e.preventDefault) {
e.preventDefault();
}
},
cancelClick: function(e) {
if (window.event) {
window.event.cancelBubble = true;
window.event.returnValue = false;
}
if (e && e.stopPropagation && e.preventDefault) {
e.stopPropagation();
e.preventDefault();
}//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
},
addEvent: function(elm, evType, fn, useCapture) {
if (elm.addEventListener) {
elm.addEventListener(evType, fn, useCapture);
return true;
} else if (elm.attachEvent) {
var r = elm.attachEvent('on' + evType, fn);
return r;
} else {
elm['on' + evType] = fn;
}//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
},
cssjs: function(a, o, c1, c2) {
switch (a) {
case 'swap':
o.className = !DOMhelp.cssjs('check', o, c1) ? o.className.replace(c2, c1) : o.className.replace(c1, c2);
break;
case 'add':
if (!DOMhelp.cssjs('check', o, c1)) { o.className += o.className ? ' ' + c1 : c1; }
break;
case 'remove':
var rep = o.className.match(' ' + c1) ? ' ' + c1 : c1;
o.className = o.className.replace(rep, '');
break;
case 'check':
var found = false;
var temparray = o.className.split(' ');
for (var i = 0; i < temparray.length; i++) {
if (temparray[i] == c1) { found = true; }
}//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
return found;
break;
}//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
},
safariClickFix: function() {
return false;
}
}//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
DOMhelp.addEvent(window, 'load', DOMhelp.init, false);
</script> 
<script type="text/javascript"> 
<!--
    sn = {
        dynamicClass: 'dyn',
        showClass: 'show',
        parentClass: 'parent',
        openClass: 'open',
        navID: 'nav',
        init: function() {
            var triggerLink;
            if (!document.getElementById || !document.createTextNode) { return; }
            var nav = document.getElementById(sn.navID);
            if (!nav) { return; }
            DOMhelp.cssjs('add', nav, sn.dynamicClass);
            var nested = nav.getElementsByTagName('ul');
            for (var i = 0; i < nested.length; i++) {
                triggerLink = nested[i].parentNode.getElementsByTagName('a')[0];
                DOMhelp.cssjs('add', triggerLink.parentNode, sn.parentClass);
                DOMhelp.addEvent(triggerLink, 'click', sn.changeSection, false);
                triggerLink.onclick = DOMhelp.safariClickFix;
                if (nested[i].parentNode.getElementsByTagName('strong').length > 0) {
                    DOMhelp.cssjs('add', triggerLink.parentNode, sn.openClass);
                    DOMhelp.cssjs('add', nested[i], sn.showClass);
                }
            }
        },
        changeSection: function(e) {
            var t = DOMhelp.getTarget(e);
            var firstList = t.parentNode.getElementsByTagName('ul')[0];
            if (DOMhelp.cssjs('check', firstList, sn.showClass)) {
                DOMhelp.cssjs('remove', firstList, sn.showClass)
                DOMhelp.cssjs('swap', t.parentNode, sn.openClass, sn.parentClass);
            } else {
                DOMhelp.cssjs('add', firstList, sn.showClass)
                DOMhelp.cssjs('swap', t.parentNode, sn.openClass, sn.parentClass);
            }
            DOMhelp.cancelClick(e);
        }
    }//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
    DOMhelp.addEvent(window, 'load', sn.init, false); 
--> 
</script>
<a href="https://www.wuming.ren">武鸣人</a>,各种信息资源免费发布,分享励志语录经典短句,减肥健身常识,各种js特效代码。网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)<hr>
<!--欢迎来到武鸣人信息资源平台,各种信息免费发布,资源共享合作共赢,分享互联网流行的励志语录经典短句,减肥健身健康小常识及打卡记录,收集各种js特效代码。-->
<script type="text/javascript" src="https://www.wuming.ren/ad/tc.js"></script>
<script type="text/javascript" src="https://www.wuming.ren/ad/a.js"></script>
<ul id="nav"> 
    <li><a href="https://www.wuming.ren">武鸣人首页</a></li> 
    <li><a href="#">武鸣人一号</a> 
        <ul> 
            <li><a href="#">大类别一</a> 
                <ul> 
                    <li><a href="#">小类别一</a> 
                        <ul> 
                            <li><a href="#">次类别一</a></li> 
                            <li><a href="#">次类别二</a></li> 
                        </ul> 
                    </li> 
                    <li><a href="#">小类别二</a></li> 
                </ul> 
            </li> 
            <li><a href="#">大类别二</a></li> 
            <li><a href="#">大类别三</a> 
                <ul> 
                    <li><a href="#">小类别一</a></li> 
                    <li><a href="#">小类别二</a></li> 
                </ul> 
            </li> 
        </ul> 
    </li> 
    <li><a href="#">武鸣人二号</a> 
        <ul> 
            <li><a href="#">大类别一</a></li> 
            <li><a href="#">大类别二</a></li> 
            <li><a href="#">大类别三</a></li> 
        </ul> 
    </li> 
    <li><a href="#">武鸣人三号</a></li> 
    <li><a href="#">武鸣人四号</a> 
        <ul> 
            <li><a href="#">大类别一</a> 
                <ul> 
                    <li><a href="#">小类别一</a></li> 
                    <li><a href="#">小类别二</a></li> 
                </ul> 
            </li> 
            <li><a href="#">大类别二</a> 
                <ul> 
                    <li><a href="#">小类别一</a></li> 
                    <li><a href="#">小类别二</a></li> 
                </ul> 
            </li> 
            <li><a href="#">大类别三</a> 
                <ul> 
                    <li><a href="#">小类别一</a></li> 
                    <li><a href="#">小类别二</a></li> 
                </ul> 
            </li> 
            <li><a href="#">大类别四</a></li> 
        </ul> 
    </li> 
    <li><a href="#">武鸣人五号</a> 
        <ul> 
            <li><a href="#">大类别一</a></li> 
            <li><a href="#">大类别二</a></li> 
        </ul> 
    </li> 
</ul>


0
0
收藏0
回帖

js实现无限级下拉菜单弹出特效 期待您的回复!

取消
载入表情清单……
载入颜色清单……
插入网络图片

取消确定

图片上传中
编辑器信息
提示信息