用javascript来获取用户客户端分辨率

我做了一个网页导航下拉菜单,用firework可以很快生成,只用把代码拷贝到页面中就可以了,可是用户端不同分辨率造成了下拉菜单位置的移动,如何在800和1024的菜单下保持正确的显示,修改js文件中的一个函数就可以,y只不用变化,只用更改x坐标变量即可

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];
  if (window.screen.width==800 && window.screen.height==600)//用来800*600分辨率设置
  {
   x = moveXbySlicePos (x-100, obj);
   y = moveYbySlicePos (y, obj);
  }
  if (window.screen.width==1024 && window.screen.height==768)// 1024分辨率设置
  {
   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   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();
}

你可能感兴趣的:(用javascript来获取用户客户端分辨率)