代码简介:
很漂亮、很常用的后台管理菜单,扩展性很好,可以随意扩充菜单单元,专用于网站后台左侧的管理菜单。
代码内容:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>拿来就能用的JS后台折叠管理菜单代码_网页代码站(www.webdm.cn)</title> <script type="text/javascript"> var myMenu; window.onload = function() { myMenu = new SDMenu("my_menu"); myMenu.init(); }; </script> <style type="text/css"> html,body{ height:100%; margin:0; font-size:12px; } span{ background:#F0DFBE; border:1px solid #ffffff; border-left:6px solid #F2A31B; 166px; height:23px; display:block; line-height:23px; padding-left:20px; } a{ padding:3px 0 3px 40px; display:block; color:#636363; } #my_menu{ 166px; background:#F7F2E4; height:100%; } div.sdmenu div.collapsed { height: 25px; } div.sdmenu div{ overflow: hidden; } </style> <script> function SDMenu(id) { if (!document.getElementById || !document.getElementsByTagName) return false; this.menu = document.getElementById(id); this.submenus = this.menu.getElementsByTagName("div"); this.remember = true; this.speed = 1; this.markCurrent = true; this.oneSmOnly = false; } SDMenu.prototype.init = function() { var mainInstance = this; for (var i = 0; i < this.submenus.length; i++) this.submenus[i].getElementsByTagName("span")[0].onclick = function() { mainInstance.toggleMenu(this.parentNode); }; if (this.markCurrent) { var links = this.menu.getElementsByTagName("a"); for (var i = 0; i < links.length; i++) if (links[i].href == document.location.href) { links[i].className = "current"; break; } } if (this.remember) { var regex = new RegExp("sdmenu_" + encodeURIComponent(this.menu.id) + "=([01]+)"); var match = regex.exec(document.cookie); if (match) { var states = match[1].split(""); for (var i = 0; i < states.length; i++) this.submenus[i].className = (states[i] == 0 ? "collapsed" : ""); } } }; SDMenu.prototype.toggleMenu = function(submenu) { if (submenu.className == "collapsed") this.expandMenu(submenu); else this.collapseMenu(submenu); }; //htp: SDMenu.prototype.expandMenu = function(submenu) { var fullHeight = submenu.getElementsByTagName("span")[0].offsetHeight; var links = submenu.getElementsByTagName("a"); for (var i = 0; i < links.length; i++) fullHeight += links[i].offsetHeight; var moveBy = Math.round(this.speed * links.length); var mainInstance = this; var intId = setInterval(function() { var curHeight = submenu.offsetHeight; var newHeight = curHeight + moveBy; if (newHeight < fullHeight) submenu.style.height = newHeight + "px"; else { clearInterval(intId); submenu.style.height = ""; submenu.className = ""; mainInstance.memorize(); } }, 30); this.collapseOthers(submenu); }; SDMenu.prototype.collapseMenu = function(submenu) { var minHeight = submenu.getElementsByTagName("span")[0].offsetHeight; var moveBy = Math.round(this.speed * submenu.getElementsByTagName("a").length); var mainInstance = this; var intId = setInterval(function() { var curHeight = submenu.offsetHeight; var newHeight = curHeight - moveBy; if (newHeight > minHeight) submenu.style.height = newHeight + "px"; else { clearInterval(intId); submenu.style.height = ""; submenu.className = "collapsed"; mainInstance.memorize(); } }, 30); }; SDMenu.prototype.collapseOthers = function(submenu) { if (this.oneSmOnly) { for (var i = 0; i < this.submenus.length; i++) if (this.submenus[i] != submenu && this.submenus[i].className != "collapsed") this.collapseMenu(this.submenus[i]); } }; SDMenu.prototype.memorize = function() { if (this.remember) { var states = new Array(); for (var i = 0; i < this.submenus.length; i++) states.push(this.submenus[i].className == "collapsed" ? 0 : 1); var d = new Date(); d.setTime(d.getTime() + (30 * 24 * 60 * 60 * 1000)); document.cookie = "sdmenu_" + encodeURIComponent(this.menu.id) + "=" + states.join("") + "; expires=" + d.toGMTString() + "; path=/"; } }; </script> </head> <body> <div style="float:left" id="my_menu" class="sdmenu"> <div> <span>网页代码站后台管理</span> <a href="/">> 网页特效</a> <a href="/">> 代码分类</a> <a href="http://www.webdm.cn">> 最新更新</a> <a href="/">> 下载排行</a> </div> <div> <span>ASP源码下载</span> <a href="/">> 聊天留言</a> <a href="/">> 企业建站</a> </div> <div> <span>PHP源码下载</span> <a href="/">> CMS系统</a> <a href="/">> 学校政府</a> <a href="/">> 影音视频</a> </div> <div> <span>ASP.NET精品源码</span> <a href="/">> 办公管理</a> <a href="http://www.webdm.cn">> 采集</a> <a href="/">> 整站程序</a> </div> <div> <span>新闻文章管理</span> <a href="/">> 办公管理</a> <a href="/">> 小偷采集</a> </div> </div> </body> </html> <br> <a href="http://www.webdm.cn">网页代码站</a> - 最专业的代码下载网站 - 致力为中国站长提供有质量的代码!
代码来自:http://www.webdm.cn/webcode/bb327b32-bf27-41ba-9758-50ab53c51ea3.html