mm_menu.js(实现鼠标移入横向显示二级菜单效果)(2)

function NS4resize() {
if (NS4sIW != window.innerWidth || NS4sIH != window.innerHeight) window.location.reload();
}
function onMenuItemOver(e, l) {
MM_clearTimeout();
l = l || this;
var a = window.ActiveMenuItem;
if (document.layers) {
   if (a) {
    a.document.bgColor = a.saveColor;
    if (a.hilite) a.hilite.visibility = "hidden";
    if (a.Menu.bgImageOver) a.background.src = a.Menu.bgImageUp;
    a.focusItem.top = -100;
    a.clicked = false;
   }
   if (l.hilite) {
    l.document.bgColor = l.menuHiliteBgColor;
    l.zIndex = 1;
    l.hilite.visibility = "inherit";
    l.hilite.zIndex = 2;
    l.document.layers[1].zIndex = 1;
    l.focusItem.zIndex = this.zIndex +2;
   }
   if (l.Menu.bgImageOver) l.background.src = l.Menu.bgImageOver;
   l.focusItem.top = this.top;
   l.focusItem.left = this.left;
   l.focusItem.clip.width = l.clip.width;
   l.focusItem.clip.height = l.clip.height;
   l.Menu.hideChildMenu(l);
} else if (l.style && l.Menu) {
   if (a) {
    a.style.backgroundColor = a.saveColor;
    if (a.hilite) a.hilite.style.visibility = "hidden";
    if (a.hiliteShim) a.hiliteShim.style.visibility = "inherit";
    if (a.Menu.bgImageUp) a.style.background = "url(" + a.Menu.bgImageUp +")";;
   }
   l.style.backgroundColor = l.menuHiliteBgColor;
   l.zIndex = 1;
   if (l.Menu.bgImageOver) l.style.background = "url(" + l.Menu.bgImageOver +")";
   if (l.hilite) {
    l.hilite.style.visibility = "inherit";
    if( l.hiliteShim ) l.hiliteShim.style.visibility = "visible";
   }
   l.focusItem.style.pixelTop = l.style.pixelTop;
   l.focusItem.style.top = l.focusItem.style.pixelTop + 'px';
   l.focusItem.style.pixelLeft = l.style.pixelLeft;
   l.focusItem.style.left = l.focusItem.style.pixelLeft + 'px';
   l.focusItem.style.zIndex = l.zIndex +1;
   l.Menu.hideChildMenu(l);
} else return;
window.ActiveMenuItem = l;
}
function onMenuItemAction(e, l) {
l = window.ActiveMenuItem;
if (!l) return;
hideActiveMenus();
if (l.mmaction) eval("" + l.mmaction);
window.ActiveMenuItem = 0;
}
function MM_clearTimeout() {
if (mmHideMenuTimer) clearTimeout(mmHideMenuTimer);
mmHideMenuTimer = null;
mmDHFlag = false;
}
function MM_startTimeout() {
if( window.ActiveMenu ) {
   mmStart = new Date();
   mmDHFlag = true;
   mmHideMenuTimer = setTimeout("mmDoHide()", window.ActiveMenu.Menu.hideTimeout);
}
}
function mmDoHide() {
if (!mmDHFlag || !window.ActiveMenu) return;
var elapsed = new Date() - mmStart;
var timeout = window.ActiveMenu.Menu.hideTimeout;
if (elapsed < timeout) {
   mmHideMenuTimer = setTimeout("mmDoHide()", timeout+100-elapsed);
   return;
}
mmDHFlag = false;
hideActiveMenus();
window.ActiveMenuItem = 0;
}
function MM_showMenu(menu, x, y, child, imgname) {
if (!window.mmWroteMenu) return;
MM_clearTimeout();
if (menu) {
   var obj = FIND(imgname) || document.images[imgname] || document.links[imgname] || document.anchors[imgname];
   x = moveXbySlicePos (x, obj);
   y = moveYbySlicePos (y, obj);
}
if (document.layers) {
   if (menu) {
    var l = menu.menuLayer || menu;
    l.top = l.left = 1;
    hideActiveMenus();
    if (this.visibility) l = this;
    window.ActiveMenu = l;
   } else {
    var l = child;
   }
   if (!l) return;
   for (var i=0; i<l.layers.length; i++) {      
    if (!l.layers[i].isHilite) l.layers[i].visibility = "inherit";
    if (l.layers[i].document.layers.length > 0) MM_showMenu(null, "relative", "relative", l.layers[i]);
   }
   if (l.parentLayer) {
    if (x != "relative") l.parentLayer.left = x || window.pageX || 0;
    if (l.parentLayer.left + l.clip.width > window.innerWidth) l.parentLayer.left -= (l.parentLayer.left + l.clip.width - window.innerWidth);
    if (y != "relative") l.parentLayer.top = y || window.pageY || 0;
    if (l.parentLayer.isContainer) {
     l.Menu.xOffset = window.pageXOffset;
     l.Menu.yOffset = window.pageYOffset;
     l.parentLayer.clip.width = window.ActiveMenu.clip.width +2;
     l.parentLayer.clip.height = window.ActiveMenu.clip.height +2;
     if (l.parentLayer.menuContainerBgColor && l.Menu.menuBgOpaque ) l.parentLayer.document.bgColor = l.parentLayer.menuContainerBgColor;
    }
   }
   l.visibility = "inherit";
   if (l.Menu) l.Menu.container.visibility = "inherit";
} else if (FIND("menuItem0")) {
   var l = menu.menuLayer || menu;
   hideActiveMenus();
   if (typeof(l) == "string") l = FIND(l);
   window.ActiveMenu = l;
   var s = l.style;
   s.visibility = "inherit";
   if (x != "relative") {
    s.pixelLeft = x || (window.pageX + document.body.scrollLeft) || 0;
    s.left = s.pixelLeft + 'px';
   }
   if (y != "relative") {
    s.pixelTop = y || (window.pageY + document.body.scrollTop) || 0;
    s.top = s.pixelTop + 'px';
   }
   l.Menu.xOffset = document.body.scrollLeft;
   l.Menu.yOffset = document.body.scrollTop;
}
if (menu) window.activeMenus[window.activeMenus.length] = l;
MM_clearTimeout();
}
function onMenuItemDown(e, l) {
var a = window.ActiveMenuItem;
if (document.layers && a) {
   a.eX = e.pageX;
   a.eY = e.pageY;
   a.clicked = true;
    }
}
function mouseupMenu(e) {
hideMenu(true, e);
hideActiveMenus();
return true;
}
function getExplorerVersion() {
var ieVers = parseFloat(navigator.appVersion);
if( navigator.appName != 'Microsoft Internet Explorer' ) return ieVers;
var tempVers = navigator.appVersion;
var i = tempVers.indexOf( 'MSIE ' );
if( i >= 0 ) {
   tempVers = tempVers.substring( i+5 );
   ieVers = parseFloat( tempVers );
}
return ieVers;
}
function mouseoutMenu() {
if ((navigator.appName == "Microsoft Internet Explorer") && (getExplorerVersion() < 4.5))
   return true;
hideMenu(false, false);
return true;
}
function hideMenu(mouseup, e) {
var a = window.ActiveMenuItem;
if (a && document.layers) {
   a.document.bgColor = a.saveColor;
   a.focusItem.top = -30;
   if (a.hilite) a.hilite.visibility = "hidden";
   if (mouseup && a.mmaction && a.clicked && window.ActiveMenu) {
     if (a.eX <= e.pageX+15 && a.eX >= e.pageX-15 && a.eY <= e.pageY+10 && a.eY >= e.pageY-10) {
     setTimeout('window.ActiveMenu.Menu.onMenuItemAction();', 500);
    }
   }
   a.clicked = false;
   if (a.Menu.bgImageOver) a.background.src = a.Menu.bgImageUp;
} else if (window.ActiveMenu && FIND("menuItem0")) {
   if (a) {
    a.style.backgroundColor = a.saveColor;
    if (a.hilite) a.hilite.style.visibility = "hidden";
    if (a.hiliteShim) a.hiliteShim.style.visibility = "inherit";
    if (a.Menu.bgImageUp) a.style.background = "url(" + a.Menu.bgImageUp +")";
   }
}
if (!mouseup && window.ActiveMenu) {
   if (window.ActiveMenu.Menu) {
    if (window.ActiveMenu.Menu.hideOnMouseOut) MM_startTimeout();
    return(true);
   }
}
return(true);
}
function hideChildMenu(hcmLayer) {
MM_clearTimeout();
var l = hcmLayer;
for (var i=0; i < l.Menu.childMenus.length; i++) {
   var theLayer = l.Menu.childMenus[i];
   if (document.layers) theLayer.visibility = "hidden";
   else {
    theLayer = FIND(theLayer);
    theLayer.style.visibility = "hidden";
    if( theLayer.Menu.menuItemHAlign != 'left' ) {
     for(var j = 0; j < theLayer.Menu.menuItemLayers.length; j++) {
      var itemLayer = theLayer.Menu.menuItemLayers[j];
      if(itemLayer.textShim) itemLayer.textShim.style.visibility = "inherit";
     }
    }
   }
   theLayer.Menu.hideChildMenu(theLayer);
}
if (l.childMenu) {
   var childMenu = l.childMenu;
   if (document.layers) {
    l.Menu.MM_showMenu(null,null,null,childMenu.layers[0]);
    childMenu.zIndex = l.parentLayer.zIndex +1;
    childMenu.top = l.Menu.menuLayer.top + l.Menu.submenuYOffset;
    if( l.Menu.vertical ) {
     if( l.Menu.submenuRelativeToItem ) childMenu.top += l.top + l.parentLayer.top;
     childMenu.left = l.parentLayer.left + l.parentLayer.clip.width - (2*l.Menu.menuBorder) + l.Menu.menuLayer.left + l.Menu.submenuXOffset;
    } else {
     childMenu.top += l.top + l.parentLayer.top;
     if( l.Menu.submenuRelativeToItem ) childMenu.left = l.Menu.menuLayer.left + l.left + l.clip.width + (2*l.Menu.menuBorder) + l.Menu.submenuXOffset;
     else childMenu.left = l.parentLayer.left + l.parentLayer.clip.width - (2*l.Menu.menuBorder) + l.Menu.menuLayer.left + l.Menu.submenuXOffset;
    }
    if( childMenu.left < l.Menu.container.clip.left ) l.Menu.container.clip.left = childMenu.left;
    var w = childMenu.clip.width+childMenu.left-l.Menu.container.clip.left;
    if (w > l.Menu.container.clip.width) l.Menu.container.clip.width = w;
    var h = childMenu.clip.height+childMenu.top-l.Menu.container.clip.top;
    if (h > l.Menu.container.clip.height) l.Menu.container.clip.height = h;
    l.document.layers[1].zIndex = 0;
    childMenu.visibility = "inherit";
   } else if (FIND("menuItem0")) {
    childMenu = FIND(l.childMenu);
    var menuLayer = FIND(l.Menu.menuLayer);
    var s = childMenu.style;
    s.zIndex = menuLayer.style.zIndex+1;
    if (document.all || window.mmIsOpera) {
     s.pixelTop = menuLayer.style.pixelTop + l.Menu.submenuYOffset;
     if( l.Menu.vertical ) {
      if( l.Menu.submenuRelativeToItem ) s.pixelTop += l.style.pixelTop;
      s.pixelLeft = l.style.pixelWidth + menuLayer.style.pixelLeft + l.Menu.submenuXOffset;
      s.left = s.pixelLeft + 'px';
     } else {
      s.pixelTop += l.style.pixelTop;
      if( l.Menu.submenuRelativeToItem ) s.pixelLeft = menuLayer.style.pixelLeft + l.style.pixelLeft + l.style.pixelWidth + (2*l.Menu.menuBorder) + l.Menu.submenuXOffset;
      else s.pixelLeft = (menuLayer.style.pixelWidth-4*l.Menu.menuBorder) + menuLayer.style.pixelLeft + l.Menu.submenuXOffset;
      s.left = s.pixelLeft + 'px';
     }
    } else {
     var top = parseInt(menuLayer.style.top) + l.Menu.submenuYOffset;
     var left = 0;
     if( l.Menu.vertical ) {
      if( l.Menu.submenuRelativeToItem ) top += parseInt(l.style.top);
      left = (parseInt(menuLayer.style.width)-4*l.Menu.menuBorder) + parseInt(menuLayer.style.left) + l.Menu.submenuXOffset;
     } else {
      top += parseInt(l.style.top);
      if( l.Menu.submenuRelativeToItem ) left = parseInt(menuLayer.style.left) + parseInt(l.style.left) + parseInt(l.style.width) + (2*l.Menu.menuBorder) + l.Menu.submenuXOffset;
      else left = (parseInt(menuLayer.style.width)-4*l.Menu.menuBorder) + parseInt(menuLayer.style.left) + l.Menu.submenuXOffset;
     }
     s.top = top + 'px';
     s.left = left + 'px';
    }
    childMenu.style.visibility = "inherit";
   } else return;
   window.activeMenus[window.activeMenus.length] = childMenu;
}
}
function hideActiveMenus() {
if (!window.activeMenus) return;
for (var i=0; i < window.activeMenus.length; i++) {
   if (!activeMenus[i]) continue;
   if (activeMenus[i].visibility && activeMenus[i].Menu && !window.mmIsOpera) {
    activeMenus[i].visibility = "hidden";
    activeMenus[i].Menu.container.visibility = "hidden";
    activeMenus[i].Menu.container.clip.left = 0;
   } else if (activeMenus[i].style) {
    var s = activeMenus[i].style;
    s.visibility = "hidden";
    s.left = '-200px';
    s.top = '-200px';
   }
}
if (window.ActiveMenuItem) hideMenu(false, false);
window.activeMenus.length = 0;
}
function moveXbySlicePos (x, img) {
if (!document.layers) {
   var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
   var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
   var par = img;
   var lastOffset = 0;
   while(par){
    if( par.leftMargin && ! onWindows ) x += parseInt(par.leftMargin);
    if( (par.offsetLeft != lastOffset) && par.offsetLeft ) x += parseInt(par.offsetLeft);
    if( par.offsetLeft != 0 ) lastOffset = par.offsetLeft;
    par = macIE45 ? par.parentElement : par.offsetParent;
   }
} else if (img.x) x += img.x;
return x;
}
function moveYbySlicePos (y, img) {
if(!document.layers) {
   var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
   var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
   var par = img;
   var lastOffset = 0;
   while(par){
    if( par.topMargin && !onWindows ) y += parseInt(par.topMargin);
    if( (par.offsetTop != lastOffset) && par.offsetTop ) y += parseInt(par.offsetTop);
    if( par.offsetTop != 0 ) lastOffset = par.offsetTop;
    par = macIE45 ? par.parentElement : par.offsetParent;
   }  
} else if (img.y >= 0) y += img.y;
return y;
}
个人感想:js比想象中的功能强大,可也比想象中的麻烦。

你可能感兴趣的:(职场,休闲,鼠标移入,mm_menu.js,菜单效果)