`
shylhd
  • 浏览: 76776 次
  • 性别: Icon_minigender_2
  • 来自: 河北
最近访客 更多访客>>
社区版块
存档分类
最新评论

js 很好的下拉菜单

阅读更多

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Phenix PanelBar</title>
<script language="javascript">
/*--------------------------------------------------|
| Phenix PanelBar | www.seu.edu.cn                   |
|---------------------------------------------------|
|                                                    |
|   I believe one day I can fly like phenix!          |
|                                                    |
| Finished: 17.11.2004                               |
|--------------------------------------------------*/

//item object
//alert("arrived here");
function PhenItem(id,pid,label,url,type,img,over,img2,over2,title,target){

    this.id=id;
    this.pid=pid;
    this.label=label;
    this.url=url;
    this.title=title;
    this.target=target;
    this.img=img;
    this.over=over;
    this.img2=img2;
    this.over2=over2;
    this.type=type;
    //this._ih = false; //is it the head item?
    this._hc = false;    //has the child item?
    this._ls = false; //has sibling item?
    this._io = false; //whether the panelbar is open?
};


//menu object
function PhenMenu(objName) {

     this.config = {

   closeSameLevel : true

};
//alert("asdsdf");
this.obj = objName;

this.items = [];

this.root = new PhenItem(-1);
 
};

//add a new item to the item array
PhenMenu.prototype.add = function(id,pid,label,url,type,img,over,img2,over2,title,target){
this.items[this.items.length] = new PhenItem(id,pid,label,url,type,img,over,img2,over2,title,target);
};

// Outputs the menu to the page
PhenMenu.prototype.toString = function() {
//alert("arrived here");
var str = '<div>\n';

if (document.getElementById) {

   str += this.addItem(this.root);

} else str += 'Browser not supported.';

str += '\n</div>';
     //alert(str);
//document.write(str);
//alert(this.items[0]._hc);
return str;

};

// Creates the menu structure
PhenMenu.prototype.addItem = function(pItem) {

var str = '';

//var n=0;

for (var n=0; n<this.items.length; n++) {
 
   if(this.items[n].pid == pItem.id){
  
    var ci = this.items[n];
    //alert(ci.pid);
    //alert(ci.id);
    this.setHS(ci);
    //alert("item:"+ci._hc);
    //alert(ci._ls);
    str += this.itemCreate(ci, n);
  
    if(ci._ls) break;
  
   }

}

return str;

};

// Creates the node icon, url and text
PhenMenu.prototype.itemCreate = function(pItem, itemId) {
//alert(pItem.type.toLowerCase());
var str = '';

     if(pItem.type == 'header')
      str = '<table width="100%" class="header" valign="middle" onmouseover="this.className=\'headerSelected\'" onmouseout="this.className=\'header\'" onclick="'+this.obj+'.o('+itemId+')"><tr><td>';

else
   str = '<table width="100%" class="item" valign="middle" onmouseover="this.className=\'itemOver\'" onmouseout="this.className=\'item\'" onclick="'+this.obj+'.o('+itemId+')"><tr><td>';

if (pItem.img) {

   str += '&nbsp;&nbsp;<img id="i' + this.obj + itemId + '" src="' + pItem.img + '" alt="" />';

}
if (pItem.url) {
   str += '<a id="s' + this.obj + itemId + '" class="navigation_item" href="' + pItem.url + '"';
   if (pItem.title) str += ' title="' + pItem.title + '"';
   if (pItem.target) str += ' target="' + pItem.target + '"';
   str += ' onmouseover="window.status=\'' + pItem.label + '\';return true;" onmouseout="window.status=\'\';return true;"';
   str += '>';
}
str += '&nbsp;&nbsp;&nbsp;&nbsp;' + pItem.label;
if (pItem.url) str += '</a>';
str += '</td></tr></table>';
//alert(pItem.url);
//alert(str);
if (pItem._hc) {
   str += '<table id="ct' + this.obj + itemId + '" width="100%" style="display:' + ((pItem._io) ? 'block' : 'none') + '; FILTER: blendTrans(Duration=3.0); VISIBILITY: hidden"><tr><td>';
   str += this.addItem(pItem);
   str += '</td></tr></table>';
   //alert(str);
   //document.write(str);
}

return str;
};


// Checks whether a item has child and if it is the last sibling
PhenMenu.prototype.setHS = function(pItem) {

var lastId;

for (var n=0; n<this.items.length; n++) {

   if (this.items[n].pid == pItem.id) pItem._hc = true;

   if (this.items[n].pid == pItem.pid) lastId = this.items[n].id;

}

if (lastId==pItem.id) pItem._ls = true;

};

// Toggle Open or close
PhenMenu.prototype.o = function(id) {
//alert(this.items.length);
var ci = this.items[id];
     //alert(ci);
//this.setHS(ci);
//alert(this.items[id]._hc);
this.itemStatus(!ci._io, id);

ci._io = !ci._io;
   
if (this.config.closeSameLevel) this.closeLevel(ci);

};

// Change the status of a item(open or closed)
PhenMenu.prototype.itemStatus = function(status, id) {

cTable = document.getElementById('ct' + this.obj + id);

if(status){
  
   cTable.filters.item(0).Apply();
   cTable.style.display = 'block';
   cTable.style.visibility = "";
   cTable.filters.item(0).Play();
}
else
   cTable.style.display = 'none';

//cDiv.style.display = (status) ? 'block': 'none';

};

// Closes all items on the same level as certain item
PhenMenu.prototype.closeLevel = function(pItem) {
                //alert(this.items[0]._hc);
for (var n=0; n<this.items.length; n++) {
             //alert(this.items[n]._hc);
   if ((this.items[n].pid == pItem.pid) && (this.items[n].id != pItem.id) && this.items[n]._hc) {
  
    this.itemStatus(false, n);

    this.items[n]._io = false;

    this.closeAllChildren(this.items[n]);

   }

}

};

PhenMenu.prototype.closeAllChildren = function(pItem) {

for (var n=0; n<this.items.length; n++) {

   if (this.items[n].pid == pItem.id && this.items[n]._hc) {

    if (this.items[n]._io) this.itemStatus(false, n);

    this.items[n]._io = false;

    this.closeAllChildren(this.items[n]); 

   }

}

};
</script>
<style>
.header {
height:25px;
FONT-FAMILY: Arial,Verdana;
background-image:url(images/sideNavCategoryBg.gif);
font-size:11px;
color: #666666;
   
}
.headerSelected {
height:25px;
FONT-FAMILY: Arial,Verdana;
background-image:url(images/sideNavCategorySelectedBg.gif);
font-size:11px;
background-repeat:repeat-x;
COLOR: #333333;
CURSOR: pointer;
}

.navigation_item {
PADDING-LEFT: 20px; FONT-SIZE: 11px; CURSOR: pointer; COLOR: #000000; FONT-FAMILY: Arial,Verdana; HEIGHT: 20px; TEXT-DECORATION: none
}
.item {
     PADDING-LEFT: 2px; FONT-SIZE: 11px; CURSOR: pointer; COLOR: #000000; FONT-FAMILY: Arial,Verdana; HEIGHT: 20px;
}
.itemOver {
PADDING-LEFT: 2px; FONT-SIZE: 11px; CURSOR: pointer; COLOR: #333333; FONT-FAMILY: Arial,Verdana; HEIGHT: 20px; font-weight:bold; background-color:#EDEDED
}
.itemSelected {
PADDING-LEFT: 20px; FONT-SIZE: 11px; CURSOR: pointer; COLOR: #000000; FONT-FAMILY: Arial,Verdana; HEIGHT: 20px; TEXT-DECORATION: underline;
}

A.headerSelected {
PADDING-RIGHT: 0px; PADDING-LEFT: 0px; BACKGROUND-IMAGE: none; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; HEIGHT: 10px
}
</style>
</head>
<body>
<table width="221" border="0" cellspacing="0" cellpadding="0">
   <tr>
     <td>
<p>Phenix panelbar</p>

<script type="text/javascript">

   p = new PhenMenu('p');
         //alert("asds");
   p.add(0,-1,'label1凤凰','','header','http://www.telerik.com/images/ProductImages//e.gif');
   p.add(1,0,'label1.1凤凰','www.sina.com.cn');
   p.add(2,0,'label1.2','www.sina.com.cn');
   p.add(3,0,'label1.3','www.sina.com.cn');
   p.add(4,0,'label1.4','www.sina.com.cn');
 
   p.add(5,-1,'label2','','header','http://www.telerik.com/images/ProductImages//c.gif');
   p.add(6,5,'label2.1','www.seu.edu.cn');
   p.add(7,5,'label2.2','www.seu.edu.cn');
   p.add(8,5,'label2.3','www.seu.edu.cn');
   p.add(9,5,'label2.4','www.seu.edu.cn');
 
   p.add(10,-1,'label3','','header','http://www.telerik.com/images/ProductImages//m.gif');
   p.add(11,10,'label3.1','www.seu.edu.cn');
   p.add(12,10,'label3.2','www.seu.edu.cn');
   p.add(13,10,'label3.3','www.seu.edu.cn');
   p.add(14,10,'label3.4','www.seu.edu.cn');
 
   p.add(15,-1,'label4','','header','http://www.telerik.com/images/ProductImages//r.gif');
   p.add(16,15,'label4.1','www.seu.edu.cn');
   p.add(17,15,'label4.2','www.seu.edu.cn');
   p.add(18,15,'label4.3','www.seu.edu.cn');
   p.add(19,15,'label4.4','www.seu.edu.cn');
         //alert(p.items.length)
   document.write(p);
 
   //p.toString();
         //alert(p.items.length);
   //delete(p);
</script> </td>
   </tr>
</table>
</body>
</html>

分享到:
评论

相关推荐

    很不错的JS菜单19款下拉式菜单

    - **Vue.js**:渐进式JavaScript框架,可以通过组件化的方式构建下拉菜单,如`v-show`或`v-if`指令。 9. **React组件** - **React**:Facebook开发的JavaScript库,使用JSX语法构建可复用的UI组件,下拉菜单可...

    JS二级横向下拉菜单

    JavaScript(JS)是一种轻量级的编程语言,广泛应用于网页和网络应用的开发,包括创建交互式的用户界面。...对于初学者,这是一个很好的学习案例,对于经验丰富的开发者,这也是一个快速实现此类功能的有效工具。

    非常小巧的JS下拉菜单代码

    通过深入研究"非常小巧的JS下拉菜单代码"这个项目,开发者可以学习到如何用JavaScript构建高效且具有良好用户体验的下拉菜单,同时了解如何处理跨浏览器兼容性问题,提升自己的前端开发技能。这个代码实例是一个很好...

    css+js动感下拉菜单,回弹效果

    "CSS+JS动感下拉菜单,回弹效果"就是一个很好的例子,它利用了这两种技术的协同作用,为用户带来更加生动活泼的导航体验。下面我们将深入探讨这个主题,了解如何通过CSS和JavaScript实现这种效果。 首先,CSS(层叠...

    javascript实现简单的下拉菜单

    ### JavaScript 实现简单下拉菜单知识点解析 #### 一、概述 本文将详细介绍如何使用JavaScript实现一个...对于初学者来说,这是一个很好的学习案例,可以帮助他们理解和实践JavaScript与HTML/CSS结合使用的基础知识。

    基于js控制的下拉式菜单[增加DEMO]

    在本案例中,下拉菜单的显示和隐藏由JavaScript控制,这使得菜单具有更好的交互反馈。 “控件”在网页开发中是指可重复使用的代码模块,它们提供了标准的用户界面元素,如按钮、输入框等。下拉菜单也是一种控件,...

    js简洁下拉菜单导航

    "js简洁下拉菜单导航"就是一个专为初学者设计的、易于理解和应用的下拉菜单解决方案。这个方案主要依赖于JavaScript(更具体地说,是jQuery库)来实现,因为jQuery简化了DOM操作和事件处理,使得代码更加简洁高效。 ...

    Web弹出下拉菜单

    - 虽然现代浏览器对HTML5、CSS3和JavaScript的支持已经很好,但为了确保跨浏览器兼容性,可能需要使用像`autoprefixer`这样的工具处理CSS前缀,或者使用`Babel`转换ES6+语法到ES5。 7. **可访问性**: - 为了使...

    一款很好的缓冲效果下拉菜单

    标题中的“一款很好的缓冲效果下拉菜单”指的是一个具有平滑动画过渡的下拉菜单设计,这种设计在用户交互时可以提供更好的用户体验。在网页设计中,缓冲效果通常指的是通过平滑过渡或渐进加载来改善用户界面动态展示...

    纯CSS下拉菜单,宽度自适应

    本主题聚焦于“纯CSS下拉菜单”,这是一种不依赖JavaScript实现的下拉菜单技术,主要利用CSS(层叠样式表)来创建动态效果。在实际应用中,这种菜单可能不是最通用的解决方案,但对那些希望深入了解CSS特性和动画...

    兼容性很好的下拉菜单

    本文将详细探讨"兼容性很好的下拉菜单"这一主题,包括其核心功能、设计特点以及实现方式。 下拉菜单的核心功能在于为用户提供方便快捷的导航体验。用户只需点击主菜单项,即可展开下级菜单,选择所需的操作或链接。...

    javascript html js 自定义多级联动下拉菜单,自定义select联动

    在JavaScript、HTML和JS的世界里,自定义多级联动下拉菜单是一种常见的交互设计,它通常用于提升用户体验,尤其是在处理复杂的数据层级结构时。本文将深入探讨如何利用这些技术实现自定义的select联动效果。 首先,...

    横向下拉菜单源码

    "横向下拉菜单"是一种创新的交互设计,它打破了传统的垂直下拉菜单模式,为用户提供了独特的操作体验。这种设计常见于网页、应用程序或者桌面软件中,尤其是在空间有限但选项较多的情况下,能有效地节省屏幕空间并...

    div模拟下拉菜单(select)jquery插件.gz

    为了解决这个问题,开发者常常使用`div`元素配合CSS和JavaScript来模拟下拉菜单,以实现更加灵活和美观的效果。在这个"div模拟下拉菜单(select)jquery插件.gz"压缩包中,包含的就是这样一个基于`div`和jQuery的...

    最高级最好用的下拉菜单

    DOPDropDownMenu - Enhanced 这个压缩包文件很可能包含了实现这一高效多级下拉菜单的源代码、文档和示例。开发者可以通过研究这个库,学习如何构建具有类似特性的下拉菜单。一般来说,这样的库会提供以下关键功能: ...

    二级下拉菜单很实用的二级下拉菜单!很实用的哦!

    在这个二级下拉菜单的实例中,JavaScript 可能被用来控制菜单项的显示与隐藏,响应用户的鼠标悬停、点击等事件,以及处理菜单的动画效果,以提供更好的用户体验。 首先,我们需要理解HTML的基本结构。在`二级下拉...

    各种下拉菜单

    下拉菜单是网页设计中常用的一种交互元素,它允许用户在有限的空间内选择多个选项,大大提升了用户体验。本文将深入探讨下拉菜单的设计原理、实现...理解并掌握这些知识点,有助于我们更好地设计和实现下拉菜单功能。

    24、Jquery纯CSS3制作华丽网站下拉菜单

    在网页设计中,下拉菜单是一种常见的交互元素,它...同时,由于主要依赖CSS3,所以该方法在现代浏览器中有着很好的兼容性和性能表现。记得在实际项目中进行充分的测试,以确保在各种设备和浏览器上的表现都符合预期。

    css多级下拉菜单

    一个“好看的多级下拉菜单”是用户界面设计中的常见元素,尤其适用于网站导航。这种菜单允许用户通过点击主菜单项来展开下一级甚至多级的子菜单,从而方便地访问深层次的内容。 创建CSS多级下拉菜单涉及的关键知识...

    下拉菜单demo

    在IT行业中,创建交互式用户界面是至...对于前端开发者来说,这是一个很好的实践项目,有助于提升网页设计和开发技能。通过研究和修改这个示例,你可以掌握创建动态、响应式菜单的关键技术,并将其应用到自己的项目中。

Global site tag (gtag.js) - Google Analytics