合Jst和Css实现了在Asp.net下XP风格的下拉菜单 - 中国WEB开发者网络 (http://www.webasp.net) -- 技术教程 (http://www.webasp.net/article/) --- 合Jst和Css实现了在Asp.net下XP风格的下拉菜单 (http://www.webasp.net/article/28/27295.htm) |
| -- 作者:未知 -- 发布日期: 2006-02-15 |
结合jst和css实现了在asp.net下xp风格的下拉菜单,效果图如下: 实现的步骤及源码如下: <%@ Page language="c#" Codebehind="default.aspx.cs" AutoEventWireup="false" Inherits="PopupMenuControlSample._default" %> default.aspx.cs代码: using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using UIControl;
namespace PopupMenuControlSample
{
/**////
PopupMenuControl.js代码: var VisibleSubMenus = '';
var MenuTimer = 0;
var CloseTimer = 0;
function EnterMenuCell(MenuCell,SubMenuTable)
{
// if the sub-menu-table is not displayed at the moment
if (SubMenuTable.style.display == 'none')
{
// then display it now
SubMenuTable.style.display = '';
// add this to the list of visible sub-menus; this is important if the user browses
// multiple cascaded sub-menus
if (VisibleSubMenus.length == 0)
VisibleSubMenus += SubMenuTable.id;
else
VisibleSubMenus += ',' + SubMenuTable.id;
}
}
//
// the user moves the mouse outside the menu cell
//
function LeaveMenuCell(MenuCell,SubMenuTable)
{
if (MenuTimer == 0)
MenuTimer = window.setInterval("CheckIfSubMenuToClose(" + SubMenuTable.id + ")", 20);
}
function LeaveSubMenuTable(SubMenuTable)
{
// get the list of visible sub-menus
var VisibleSubMenusArray = VisibleSubMenus.split(",");
// get the last visible sub-menu
var LastVisibleSubMenu = VisibleSubMenusArray[VisibleSubMenusArray.length - 1];
if ((SubMenuTable.style.display != 'none') & (LastVisibleSubMenu == SubMenuTable.id))
{
// closes the sub-menu table
CloseSubMenu(SubMenuTable);
if (MenuTimer == 0)
MenuTimer = window.setInterval("CloseAllSubMenus()", 20);
}
}
function CloseAllSubMenus()
{
// first clear the timer
if (MenuTimer != 0)
{
window.clearInterval(MenuTimer);
MenuTimer = 0;
}
// check if we have any sub-menus open
if (VisibleSubMenus.length > 0)
{
// get the list of visible sub-menus
var VisibleSubMenusArray = VisibleSubMenus.split(",");
// now loop through all visible sub-menus and close them too
for (Count=0; Count < visiblesubmenusarray.length; Count++)
{
// get a reference to the visible sub-menu
var SubMenu = document.getElementById(VisibleSubMenusArray[Count]);
// and now hide it
SubMenu.style.display = 'none';
}
// reset the list of visible sub-menus
VisibleSubMenus = '';
}
}
//
// the user moves the mosue cursor over the sub-menu table
//
function EnterSubMenuTable(SubMenuTable)
{
if (MenuTimer != 0)
{
window.clearInterval(MenuTimer);
MenuTimer = 0;
}
}
function CheckIfSubMenuToClose(SubMenuTable)
{
// first clear the timer itself
if (MenuTimer != 0)
{
window.clearInterval(MenuTimer);
MenuTimer = 0;
}
// now close the sub-menu table
CloseSubMenu(SubMenuTable);
}
//
// closes the sub-menu table and removes it from the list of visible sub-menus
//
function CloseSubMenu(SubMenuTable)
{
// now close the sub-menu
SubMenuTable.style.display = 'none';
// get the list of visible sub-menus
var VisibleSubMenusArray = VisibleSubMenus.split(",");
// now we rebuild the list of visible sub-menus by excluding the sub-menu we
// just closed
VisibleSubMenus = '';
// loop through all existing sub-menus
for (Count=0; Count < visiblesubmenusarray.length; Count++)
// if the sub-menu is the same as the one we just closed then ignore it;
// otherwise add it again
if (VisibleSubMenusArray[Count] != SubMenuTable.id)
if (VisibleSubMenus.length > 0)
VisibleSubMenus += "," + VisibleSubMenusArray[Count];
else
VisibleSubMenus = VisibleSubMenusArray[Count];
}
function SetControlPosition(SubMenuTable,ParentTable,ParentCell,ParentMenuDirection,OffsetX,OffsetY)
{
// we position the control absolute
SubMenuTable.style.position = 'absolute';
// parent menu is horizontal, so we position the sub-menu at left/bottom
if (ParentMenuDirection == 'Horizontal')
{
SubMenuTable.style.left = ParentTable.offsetLeft + ParentCell.offsetLeft - 1;
SubMenuTable.style.top = ParentTable.offsetTop + ParentTable.offsetHeight - 1;
}
else
// parent menu is vertical, so we position the sub-menu at right/top
if (ParentMenuDirection == 'Vertical')
{
SubMenuTable.style.left = ParentTable.offsetLeft + ParentTable.offsetWidth - 1;
SubMenuTable.style.top = ParentTable.offsetTop + ParentCell.offsetTop - 1;
}
// there is no parent-menu; this is a popup menu which will be positioned in the
// middle of the owning control
else
{
SubMenuTable.style.left = ParentTable.offsetLeft + (ParentTable.offsetWidth / 2) + 1 + Number(OffsetX);
SubMenuTable.style.top = ParentTable.offsetTop + (ParentTable.offsetHeight / 2) + 1 + Number(OffsetY);
// add any body margin we have
SubMenuTable.style.left = Number(SubMenuTable.style.left.replace('px','')) + Number(document.body.leftMargin);
SubMenuTable.style.top = Number(SubMenuTable.style.top.replace('px','')) + Number(document.body.topMargin);
}
}
function ShowPopupMenu(PopupOwnerControl,PopupTableControl,OffsetX,OffsetY)
{
// position the popup menu in the middle of the owner control
SetControlPosition(PopupTableControl, PopupOwnerControl, null, 'popup', OffsetX, OffsetY);
// show the popup-menu
PopupTableControl.style.display = '';
// give the popup menu table the focus so we know when the user clicks anywhere
// else (the control looses then the focus
PopupTableControl.focus();
}
function ClosePopupMenu(PopupOwnerControl,PopupTableControl)
{
if (CloseTimer == 0)
CloseTimer = window.setInterval("ClosePopupMenuDelayed(" + PopupOwnerControl.id + "," + PopupTableControl.id + ")", 190);
}
function ClosePopupMenuDelayed(PopupOwnerControl,PopupTableControl)
{
// clears first the timer
if (CloseTimer != 0)
{
window.clearInterval(CloseTimer);
CloseTimer = 0;
}
// we hide the popup menu
PopupTableControl.style.display = 'none';
// close any open sub-menu
CloseAllSubMenus();
}
PopupMenuControl.css代码:
.PopupMenuTableStyle
{}{
border: groove 2px white;
background-color: black;
position: relative;
left: 0px;
top: 0px;
}
.PopupMenuRowStyle
{}{
vertical-align: middle;
}
.PopupMenuCellStyle
{}{
background-color: #ececec;
text-align: left;
width: 180px;
height: 20px;
}
.PopupMenuCellHighlightedStyle
{}{
background-color: #ccccff;
text-align: left;
width: 180px;
height: 20px;
}
.PopupMenuLinkStyle
{}{
font: normal normal bold small/normal Arial;
text-decoration: none;
white-space: nowrap;
color: blue;
cursor: hand;
line-height: 18px;
}
.PopupMenuLinkHighlightedStyle
{}{
font: normal normal bolder small/normal Arial;
text-decoration: none;
white-space: nowrap;
color: #ffffcc;
color: blue;
cursor: hand;
line-height: 18px;
}
.MenuSeparatorCellStyle
{}{
background-color: #ececec;
height: 1px;
padding: 0px 0px 0px 0px;
margin: 0px 0px 0px 0px;
}
.MenuSeparatorStyle
{}{
border-top: ridge 1px;
width: 100%;
color: white;
height: 1px;
}
.PopupMenuImageBarStyle
{}{
background-color: #cccccc;
width: 24px;
}
|
| webasp.net |