自编一个简单的Web菜单

效果:在frameset中Banner菜单+左边平滑菜单。

测试页面:

<body>
  <table class="fixed-table" height="100%">
   <tr>
    <td width="150" valign="top" style="border-right: solid 1px">
     <div id="abc" style="overflow: auto"></div>
    </td>
    <td>
     <iframe id="operArea" name="operArea" width="100%" height="100%"
      frameborder="no" scrolling="no"></iframe>
    </td>
   </tr>
  </table>
 </body>

 <script language="javascript">
 var menu = new PlainMenu("aaa");
    menu.addBanner("B1", "结算报表");
    menu.addItem("I1", "结算日报", "", "B1");
    menu.addItem("I2", "结算月报", "", "B1");
    menu.addItem("I3", "结算年报", "", "B1");
    menu.addBanner("B2", "收支报表");
    menu.addItem("I4", "收支日报", "", "B2");
    menu.addItem("I5", "收支月报", "../../reports/queryMonthy_pf.jsp", "B2");
    menu.addItem("I6", "收支年报", "../../reports/queryYear_pf.jsp", "B2");
    menu.addBanner("B3", "客户分析报表");
    menu.addItem("I7", "客户交易统计日报", "", "B3");
    menu.addItem("I8", "客户贡献度月报", "", "B3");
    menu.addItem("I9", "客户贡献度年报", "", "B3");

    abc.appendChild(menu.object);
</script>

 

----------下面是js代码------------------------------------------

var ctxPath = "/b2bdemo";
function PlainMenu(id){
    this.object = new Element("TABLE",{"id":id});
    this.item_icon1 = ctxPath+"/images/1.gif";
    this.item_icon2 = ctxPath+"/images/2.gif";
}
PlainMenu.prototype.setTarget=function(frame){
    this.target = frame;
}
PlainMenu.prototype.addItem=function(_id,text,href,parentId){
    var tr = this.object.insertRow(-1);
    var td = $(tr.insertCell(-1));
    td.setAttribute("id", _id);
    td.addClassName("menu-td");
    var item = new Element("span").update(text);
    item.addClassName("plain-menuItem");
    td.insert({bottom:item});
    td.insert({bottom:"&nbsp;<img src='"+this.item_icon1+"'>"});
    td.menu = this;
    td.observe("click", function(event){
        this.menu.alterFocusItem(_id);
        document.getElementById("operArea").src = href;   //this.target
    });
    if (parentId != undefined){
        td.parentId = parentId;
        tr.style.display = "none";
    }

    tr = this.object.insertRow(-1);
    td = $(tr.insertCell(-1));
    td.addClassName("menuItem-separator");
    if (parentId != undefined){
        td.parentId = parentId;
        tr.style.display = "none";
    }
}
PlainMenu.prototype.addBanner=function(_id,text,layer){
    var td = this.object.insertRow(-1).insertCell(-1);
    td = $(td).update(text);
    td.setAttribute("id", _id);
    td.addClassName("plain-menuBanner");
    td.menu = this;
    td.expand = false;
    td.layer =layer;
    td.observe("click", function(event){
        this.menu.expand(_id);
        this.menu.alterFocusItem(_id);
    });
}
PlainMenu.prototype.getChildren=function(parentId){
    var target = new Array();
    var trObjs = this.object.rows;
    for (var i=0,len=trObjs.length; i<len; i++){
        var td = $(trObjs[i].cells[0]);
        if (td.parentId == parentId){
            target.push(trObjs[i]);
        }
    }
    return target;
}
PlainMenu.prototype.alterFocusItem=function(_id){
    if (this.itemId != _id){
        var prevItem = $(this.itemId);
        var item = $(_id);
        var isBanner = item.classNames().include("plain-menuBanner");
        if (prevItem != null){
            var children = prevItem.immediateDescendants();
            if (prevItem.classNames().include("plain-menuBanner")){
                if (isBanner){
                    this.expand(this.itemId);
                }
            }else{
                children[0].className = "plain-menuItem";
                children[1].src = this.item_icon1;
                if (prevItem.parentId && isBanner){
                    this.expand(prevItem.parentId);
                }
            }
        }
        if (isBanner){
           
        }else{
            var children = item.immediateDescendants();
            children[0].className = "focus-plain-menuItem";
            children[1].src = this.item_icon2;
        }
        this.itemId = _id;
    }
}
PlainMenu.prototype.expand=function(_id){
    var children = this.getChildren(_id);
    var expand = !$(_id).expand;
    $(_id).expand = expand;
    for (var i=0,len=children.length; i<len; i++){
        children[i].style.display = (expand) ? "inline" : "none";
    }
}


var scroll_timer;
function SlideMenu(id){
    this.object = new Element("DIV",{"id":id});
    this.object.addClassName("slide-menu");
    this.object.insert({top: '<span class="menu-arrow" title="Slide Left" οnclick="scrollShortMenu(-1)">&lt;&lt;</span>'});
    this.object.insert({bottom: '<div style="display:inline"></div>'});
    this.object.insert({bottom: '<span class="menu-arrow" title="Slide Right" οnclick="scrollShortMenu(1)">&gt;&gt;</span>'});
};
SlideMenu.prototype.setTarget=function(frame){
    this.target = frame;
}
SlideMenu.prototype.addItem=function(_id,text,href,icon){
    var slide_div = this.object.descendants()[1];
    slide_div.insert({bottom: '<span class="spanItem"></span>'});
    if (icon){  slide_div.insert({bottom: '<img src="'+icon+'">'}); }
    if (text.length < 5){
        text += "&nbsp;";
    }
    var elt = new Element("SPAN", {"id":_id}).update("&nbsp;"+text+"&nbsp;");
    elt.addClassName("slide-menuItem");
    slide_div.insert({bottom: elt});

    elt.menu = this;
    elt.observe("click", function(event){
        this.className = "focus-slide-menuItem";
        this.previousSiblings()[0].className = "focus-spanItem";
        var prevItem = $(this.menu.itemId);
        if (prevItem!=null && prevItem!=this){
            prevItem.className = "slide-menuItem";
            prevItem.previousSiblings()[0].className = "spanItem";
        }
        this.menu.itemId = _id;
        eval(this.menu.target).location = href;
    });
};
function scrollShortMenu(arrow){
   if (shortMenu.scrollLeft>=0 && parseInt(arrow) < 0){   //to left
      shortMenu.scrollLeft -= 5;
   }else{   // to right
      shortMenu.scrollLeft += 5;
   }
   if (shortMenu.scrollLeft >= shortMenu.scrollWidth - 600 || shortMenu.scrollLeft<=0){
      stopScroll();
   }
   scroll_timer = window.setTimeout("scrollShortMenu("+arrow+")",50);
}
function stopScroll(){
   window.clearTimeout(scroll_timer);
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值