用javascript來取得用戶客戶端分辨率
發(fā)表時間:2024-01-17 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]我做了一個網(wǎng)頁導(dǎo)航下拉菜單,用firework可以很快生成,只用把代碼拷貝到頁面中就可以了,可是用戶端不同分辨率造成了下拉菜單位置的移動,如何在800和1024的菜單下保持正確的顯示,修改js文件中的一個函數(shù)就可以,y只不用變化,只用更改x坐標(biāo)變量即可 function MM_showMenu(m...
我做了一個網(wǎng)頁導(dǎo)航下拉菜單,用firework可以很快生成,只用把代碼拷貝到頁面中就可以了,可是用戶端不同分辨率造成了下拉菜單位置的移動,如何在800和1024的菜單下保持正確的顯示,修改js文件中的一個函數(shù)就可以,y只不用變化,只用更改x坐標(biāo)變量即可
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分辨率設(shè)置
{
x = moveXbySlicePos (x-100, obj);
y = moveYbySlicePos (y, obj);
}
if (window.screen.width==1024 && window.screen.height==768)// 1024分辨率設(shè)置
{
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();
}