function MenuBar(container) { this.Container = container; // 容器 this.Groups = new Array(); // Group集合 this.SelectedIndex = 0; // 选中项 this.MoveIndent = 100; var timerId = null; var htmlObject = null; var owner = this; // 增加Group // this.Add = function(group) { group.MenuBar = this; group.Index = this.Groups.length; this.Groups[this.Groups.length] = group; } // 初始化 // this.Init = function() { if (this.Container != null) { if (htmlObject == null) { this.Container.appendChild(this.GetHtmlObject()); } for (var i=0; i preGroupCaptionHeight) { var indent = this.MoveIndent; if (preGroupHeight - this.MoveIndent < 0) { indent = preGroupHeight - preGroupCaptionHeight; } preGroup.SetHeight(preGroupHeight - indent); group.SetHeight(groupHeight + indent); var handler = function (){owner.ScrollMenuBar(index)} timerId = window.setTimeout(handler, 10); } else { this.SelectedIndex = index; this.Reload(); } } } // 重新计算位置 // this.Reload = function() { this.ClearTimer(); // 计算选中组高度 // var selectedGroupHeight = this.Container.clientHeight-37; for (var i=0; i 0 && selectedGroup != null) { selectedGroup.SetHeight(selectedGroupHeight); selectedGroup.ShowDrowdownButton(); } } // 获取Html对象 // this.GetHtmlObject = function() { if (htmlObject == null) { var obj = document.createElement("div"); obj.className = "left-menuBar"; var leftTitlecontent = document.createElement("div"); leftTitlecontent.className="left-title-container"; obj.appendChild(leftTitlecontent); imgcontent = document.createElement("span"); leftTitlecontent.appendChild(imgcontent); textcontent = document.createElement("h1"); textcontent.innerHTML = "菜单列表"; leftTitlecontent.appendChild(textcontent); clickcontent = document.createElement("div"); clickcontent.className="clickcontent-title"; leftTitlecontent.appendChild(clickcontent); for (var i=0; i clientHeight) } this.ShowDrowdownButton = function() { var height = this.GetHeight(); var captionHeight = this.GetCaptionHeight(); var pos = getPostion(htmlObject); // 出现上箭头 // if (this.CanScrollUp()) { imgScrollUp.style.display = "block"; imgScrollUp.style.left = objItems.offsetWidth - 16 - 4; imgScrollUp.style.top = pos.top + captionHeight - 24; imgScrollUp.onmousedown = function() { owner.MenuScrollUp(); } imgScrollUp.onmouseup = function() { owner.MenuScrollStop(); } } else { imgScrollUp.style.display = "none"; this.MenuScrollStop(); } // 出现下箭头 // if (this.CanScrollDown()) { imgScrollDown.style.display = "block"; imgScrollDown.style.left = objItems.offsetWidth - 20; imgScrollDown.style.top = height - 20; imgScrollDown.onmousedown = function() { owner.MenuScrollDown(); } imgScrollDown.onmouseup = function() { owner.MenuScrollStop(); } } else { imgScrollDown.style.display = "none"; this.MenuScrollStop(); } } this.MenuScroll = function(direction) { if (this.MenuBar == null || this.Index != this.MenuBar.SelectedIndex) { return; } var top = 0; if (direction == "up") { if (!this.CanScrollUp() || topMenuIndex == 0) { return; } topMenuIndex--; } else { if (!this.CanScrollDown() || topMenuIndex == this.Items.length) { return; } topMenuIndex++; } for (var i=0; i= 120) owner.MenuScroll("up"); else if (event.wheelDelta <= -120) owner.MenuScroll("down"); } objCaption = document.createElement("div"); obj.appendChild(objCaption); objCaption.className = "left-nav-container"; objCaption.onselectstart = function(){return false;} imgScrollDown = new Image(); obj.appendChild(imgScrollDown); imgScrollDown.src = "../resources/images/fw/left/scrolldown.gif"; imgScrollDown.className = "left-scrollButton"; imgScrollUp = new Image(); obj.appendChild(imgScrollUp); imgScrollUp.src = "../resources/images/fw/left/scrollup.gif"; imgScrollUp.className = "left-scrollButton"; imgcontent = document.createElement("span"); objCaption.appendChild(imgcontent); textcontent = document.createElement("h1"); textcontent.innerHTML = this.Text; objCaption.appendChild(textcontent); clickcontent = document.createElement("div"); objCaption.appendChild(clickcontent); objItems = document.createElement("div"); objItems.className = "left-menuItems"; obj.appendChild(objItems); for (var i=0; i