Добрый день! Может, мне кто поможет, а то я уже с ума начинаю сходить… :sorry:
Я нашла скрип «выпадающего» меню для сайта. Фон, цвет ссылок и т.п. меняется без видимых проблем… А проблемы возникают при добавлении основных ссылок: при наличии 4-х ссылок, скрипт работает, как только, добавляю 5-ю, работать перестает… Ни как не пойму в чем причина.
Может, кто знает, в чем причина? Буду очень благодарна советам, по устранеию этой неприятности-))) :agree:
Вот код работающего скрипта:
<html>
<body>
<SCRIPT LANGUAGE="JavaScript">
var isDOM = false, isNS4 = false;
if (document.all) var isDOM = true, docObj = 'document.all.', styObj = '.style';
else if (document.layers) var isNS4 = true, docObj = 'document.', styObj = '';
var popTimer = 0;
var litNow = new Array();
function popOver(menuNum, itemNum) {
clearTimeout(popTimer);
hideAllBut(menuNum);
litNow = getTree(menuNum, itemNum);
changeCol(litNow, true);
targetNum = menu[menuNum][itemNum].target;
if (targetNum > 0) {
targetName = menu[targetNum][0].id;
menuName = menu[menuNum][0].id;
menuRef = eval(docObj + menuName + styObj);
thisX = parseInt(menuRef.left);
thisY = parseInt(menuRef.top);
itemPath = docObj;//osw
if (isNS4) itemPath += menuName + '.document.';
itemRef = eval(itemPath + menuName + itemNum.toString() + styObj);
thisX += parseInt(itemRef.left);
thisY += parseInt(itemRef.top);
with (eval(docObj + targetName + styObj)) {
left = parseInt(thisX + menu[targetNum][0].x);
top = parseInt(thisY + menu[targetNum][0].y);
visibility = 'visible';
}
}
}
function popOut(menuNum, itemNum) {
popTimer = setTimeout('hideAllBut(0)', 500);
}
function getTree(menuNum, itemNum) {
itemArray = new Array(menu.length);
while(1) {
itemArray[menuNum] = itemNum;
if (menuNum == 0) return itemArray;
itemNum = menu[menuNum][0].parentItem;
menuNum = menu[menuNum][0].parentMenu;
}
}
function changeCol(changeArray, isOver) {
for (menuCount = 0; menuCount < changeArray.length; menuCount++) {
if (changeArray[menuCount]) {
thisMenu = menu[menuCount][0].id;
thisItem = thisMenu + changeArray[menuCount].toString();
newCol = isOver ? menu[menuCount][0].overCol : menu[menuCount][0].backCol;
if (isDOM) document.all[thisItem].style.backgroundColor = newCol;
if (isNS4) document[thisMenu].document[thisItem].bgColor = newCol;
}
}
}
function hideAllBut(menuNum) {
var keepMenus = getTree(menuNum, 1);
for (count = 0; count < menu.length; count++)
if (!keepMenus[count])
eval(docObj + menu[count][0].id + styObj + '.visibility = "hidden"');
changeCol(litNow, false);
}
var endDL = isDOM ? '</div>' : '</layer>';
function Menu(id, x, y, width, overCol, backCol, borderCol) {
this.id = id;
this.x = x;
this.y = y;
this.width = width;
this.overCol = overCol;
this.backCol = backCol;
this.borderCol = borderCol;
this.parentMenu = null;
this.parentItem = null;
}
function Item(text, href, height, target) {
this.text = text;
this.href = href;
this.height = height;
this.target = target;
}
function startDL(id, x, y, width, height, vis, back, border, zIndex, extraProps) {
if (isDOM) {
str = '<div id="' + id + '" style="position: absolute; left: ' + x + '; top: ' + y +
'; width: ' + width + '; height: ' + height + '; visibility: ' + vis + '; ';
if (back) str += 'background: ' + back + '; ';
if (border) str += 'padding: 3px; border: 1px solid ' + border + '; ';
if (zIndex) str += 'z-index: ' + zIndex + '; ';
str += '" ';
}
if (isNS4) {
str = '<layer id="' + id + '" left="' + x + '" top="' + y + '" width="' + width +
'" height="' + height + '" visibility="' + vis + '" ';
if (back) str += 'bgcolor="' + back + '" ';
if (border) str += 'style="border: 1px solid ' + border + '" ';
if (zIndex) str += 'z-index="' + zIndex + '" ';
}
return str + extraProps + '>';
}
function mouseProps(currMenu, currItem) {
return 'onMouseOver="popOver(' + currMenu + ',' + currItem + ')" onMouseOut="popOut(' + currMenu + ',' + currItem + ')"';
}
function writeMenus(customRoot, popInd) {
for (currMenu = 0; currMenu < menu.length; currMenu++) {
showMenu = true;
if ((currMenu == 0) && customRoot) {
document.write(customRoot);
showMenu = false;
}
with (menu[currMenu][0]) {
//fantasyflash.ru
menuHTML = startDL(id, x, y, 0, 0, 'hidden', null, null, 100, '');
var back = backCol, bord = borderCol, currWidth = width - 8;
}
itemPos = 0;
for (currItem = 1; currItem < menu[currMenu].length; currItem++) {
trigID = menu[currMenu][0].id + currItem.toString();
with (menu[currMenu][currItem]) {
menuHTML += startDL(trigID, 0, itemPos, 0, 0, 'inherit', back, bord, 100, mouseProps(currMenu, currItem)) + '<table width="' + currWidth + '" border="0" cellspacing="0" cellpadding="0"><tr>' + '<td align="left"><a class="Item" href="' + href + '">' + text + '</a></td>' + '<td class="Item" align="right">' + (target ? popInd : '') + '</td></tr></table>' + endDL;
if (target > 0) {
menu[target][0].parentMenu = currMenu;
menu[target][0].parentItem = currItem;
}
itemPos += height;
}
}
if (showMenu) document.write(menuHTML + endDL);
litNow[currMenu] = null;
}
}
</script>
<style>
<!--
.Item { text-decoration: none; color: #FFFFFF; font: 12px Arial, Helvetica }
-->
</style>
<SCRIPT LANGUAGE="JavaScript">
var menu = new Array();
var defOver = '#666699', defBack = '#003366', defBorder = '#000000';
var defHeight = 22;
menu[0] = new Array();
menu[0][0] = new Menu('rootMenu', 0, 0, 80, '#666699', '#666699', defBorder);
menu[0][1] = new Item('Linka1', '#', defHeight, 1);
menu[0][2] = new Item('Linka2', '#', defHeight, 2);
menu[0][3] = new Item('Linka3', '#', defHeight, 3);
menu[0][4] = new Item('Linka4', '#', defHeight, 4);
menu[1] = new Array();
menu[1][0] = new Menu('fileMenu', 0, 22, 80, defOver, defBack, defBorder);
menu[1][1] = new Item('Linka4', '#', defHeight, 0);
menu[1][2] = new Item('Linka5', '#', defHeight, 0);
menu[1][3] = new Item('Linka6', '#', defHeight, 0);
menu[1][4] = new Item('Linka7', '#', defHeight, 0);
menu[1][5] = new Item('Linka8', '#', defHeight, 0);
menu[2] = new Array();//fantasyflash.ru
menu[2][0] = new Menu('editMenu', 0, 22, 80, defOver, defBack, defBorder);
menu[2][1] = new Item('Linka9', '#', defHeight, 0);
menu[2][2] = new Item('Linka10', '#', defHeight, 0);
menu[2][3] = new Item('Linka11', '#', defHeight, 0);
menu[3] = new Array();
menu[3][0] = new Menu('helpMenu', 0, 22, 80, defOver, defBack, defBorder);
menu[3][1] = new Item('Linka12', '#', defHeight, 0);
menu[3][2] = new Item('Linka13', '#', defHeight, 0);
menu[3][3] = new Item('Linka14', '#', defHeight, 0);
menu[4] = new Array();//osw
menu[4][0] = new Menu('reopenMenu', 0, 22, 80, defOver, defBack, defBorder);
menu[4][1] = new Item('Linka15', '#', defHeight, 0);
menu[4][2] = new Item('Linka16', '#', defHeight, 0);
menu[4][3] = new Item('Linka17', '#', defHeight, 0);
newRoot = startDL('rootMenu', 0, 0, '100%', 17, 'hidden', '#666699', null, 100, '');
newRoot += startDL('rootMenu1', 5, 0, 40, 17, 'inherit', '#666699', null, 100, mouseProps(0, 1));
newRoot += '<span class="Item"> Linka 1</span>' + endDL;
newRoot += startDL('rootMenu2', 55, 0, 40, 17, 'inherit', '#666699', null, 100, mouseProps(0, 2));
newRoot += '<span class="Item"> Linkа 2</span>' + endDL;
newRoot += startDL('rootMenu3', 105, 0, 40, 17, 'inherit', '#666699', null, 100, mouseProps(0, 3));
newRoot += '<span class="Item"> Linkа 3</span>' + endDL;
newRoot += startDL('rootMenu4', 159, 0, 40, 17, 'inherit', '#666699', null, 100, mouseProps(0, 4));
newRoot += '<span class="Item"> Linkа 4</span>' + endDL;
newRoot += endDL;//osw
writeMenus(newRoot, '>');
if (isNS4) document.captureEvents(Event.CLICK);
document.onclick = clickHandle;
function clickHandle(evt) {
if (isNS4) document.routeEvent(evt);
hideAllBut(0);
}
eval(docObj + menu[0][0].id + styObj + '.visibility = "visible"');
function moveRoot() {
rM = eval(docObj + menu[0][0].id + styObj);
if (parseInt(rM.top) < 40) rM.top = 40;
else rM.top = 0;
}</script>
</body>
</html>
А здесь, скрипт уже не работает:
<html>
<!-- Creation date: 30.07.2007 -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title></title>
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="dnsoft">
</head>
<body>
<body>
<SCRIPT LANGUAGE="JavaScript">
var isDOM = false, isNS4 = false;
if (document.all) var isDOM = true, docObj = 'document.all.', styObj = '.style';
else if (document.layers) var isNS4 = true, docObj = 'document.', styObj = '';
var popTimer = 0;
var litNow = new Array();
function popOver(menuNum, itemNum) {
clearTimeout(popTimer);
hideAllBut(menuNum);
litNow = getTree(menuNum, itemNum);
changeCol(litNow, true);
targetNum = menu[menuNum][itemNum].target;
if (targetNum > 0) {
targetName = menu[targetNum][0].id;
menuName = menu[menuNum][0].id;
menuRef = eval(docObj + menuName + styObj);
thisX = parseInt(menuRef.left);
thisY = parseInt(menuRef.top);
itemPath = docObj;//osw
if (isNS4) itemPath += menuName + '.document.';
itemRef = eval(itemPath + menuName + itemNum.toString() + styObj);
thisX += parseInt(itemRef.left);
thisY += parseInt(itemRef.top);
with (eval(docObj + targetName + styObj)) {
left = parseInt(thisX + menu[targetNum][0].x);
top = parseInt(thisY + menu[targetNum][0].y);
visibility = 'visible';
}
}
}
function popOut(menuNum, itemNum) {
popTimer = setTimeout('hideAllBut(0)', 500);
}
function getTree(menuNum, itemNum) {
itemArray = new Array(menu.length);
while(1) {
itemArray[menuNum] = itemNum;
if (menuNum == 0) return itemArray;
itemNum = menu[menuNum][0].parentItem;
menuNum = menu[menuNum][0].parentMenu;
}
}
function changeCol(changeArray, isOver) {
for (menuCount = 0; menuCount < changeArray.length; menuCount++) {
if (changeArray[menuCount]) {
thisMenu = menu[menuCount][0].id;
thisItem = thisMenu + changeArray[menuCount].toString();
newCol = isOver ? menu[menuCount][0].overCol : menu[menuCount][0].backCol;
if (isDOM) document.all[thisItem].style.backgroundColor = newCol;
if (isNS4) document[thisMenu].document[thisItem].bgColor = newCol;
}
}
}
function hideAllBut(menuNum) {
var keepMenus = getTree(menuNum, 1);
for (count = 0; count < menu.length; count++)
if (!keepMenus[count])
eval(docObj + menu[count][0].id + styObj + '.visibility = "hidden"');
changeCol(litNow, false);
}
var endDL = isDOM ? '</div>' : '</layer>';
function Menu(id, x, y, width, overCol, backCol, borderCol) {
this.id = id;
this.x = x;
this.y = y;
this.width = width;
this.overCol = overCol;
this.backCol = backCol;
this.borderCol = borderCol;
this.parentMenu = null;
this.parentItem = null;
}
function Item(text, href, height, target) {
this.text = text;
this.href = href;
this.height = height;
this.target = target;
}
function startDL(id, x, y, width, height, vis, back, border, zIndex, extraProps) {
if (isDOM) {
str = '<div id="' + id + '" style="position: absolute; left: ' + x + '; top: ' + y +
'; width: ' + width + '; height: ' + height + '; visibility: ' + vis + '; ';
if (back) str += 'background: ' + back + '; ';
if (border) str += 'padding: 3px; border: 1px solid ' + border + '; ';
if (zIndex) str += 'z-index: ' + zIndex + '; ';
str += '" ';
}
if (isNS4) {
str = '<layer id="' + id + '" left="' + x + '" top="' + y + '" width="' + width +
'" height="' + height + '" visibility="' + vis + '" ';
if (back) str += 'bgcolor="' + back + '" ';
if (border) str += 'style="border: 1px solid ' + border + '" ';
if (zIndex) str += 'z-index="' + zIndex + '" ';
}
return str + extraProps + '>';
}
function mouseProps(currMenu, currItem) {
return 'onMouseOver="popOver(' + currMenu + ',' + currItem + ')" onMouseOut="popOut(' + currMenu + ',' + currItem + ')"';
}
function writeMenus(customRoot, popInd) {
for (currMenu = 0; currMenu < menu.length; currMenu++) {
showMenu = true;
if ((currMenu == 0) && customRoot) {
document.write(customRoot);
showMenu = false;
}
with (menu[currMenu][0]) {
//fantasyflash.ru
menuHTML = startDL(id, x, y, 0, 0, 'hidden', null, null, 100, '');
var back = backCol, bord = borderCol, currWidth = width - 8;
}
itemPos = 0;
for (currItem = 1; currItem < menu[currMenu].length; currItem++) {
trigID = menu[currMenu][0].id + currItem.toString();
with (menu[currMenu][currItem]) {
menuHTML += startDL(trigID, 0, itemPos, 0, 0, 'inherit', back, bord, 100, mouseProps(currMenu, currItem)) + '<table width="' + currWidth + '" border="0" cellspacing="0" cellpadding="0"><tr>' + '<td align="left"><a class="Item" href="' + href + '">' + text + '</a></td>' + '<td class="Item" align="right">' + (target ? popInd : '') + '</td></tr></table>' + endDL;
if (target > 0) {
menu[target][0].parentMenu = currMenu;
menu[target][0].parentItem = currItem;
}
itemPos += height;
}
}
if (showMenu) document.write(menuHTML + endDL);
litNow[currMenu] = null;
}
}
</script>
<style>
<!--
.Item { text-decoration: none; color: #FFFFFF; font: 12px Arial, Helvetica }
-->
</style>
<SCRIPT LANGUAGE="JavaScript">
var menu = new Array();
var defOver = '#666699', defBack = '#003366', defBorder = '#000000';
var defHeight = 22;
menu[0] = new Array();
menu[0][0] = new Menu('rootMenu', 0, 0, 80, '#666699', '#666699', defBorder);
menu[0][1] = new Item('Linka1', '#', defHeight, 1);
menu[0][2] = new Item('Linka2', '#', defHeight, 2);
menu[0][3] = new Item('Linka3', '#', defHeight, 3);
menu[0][4] = new Item('Linka4', '#', defHeight, 4);
menu[0][5] = new Item('Linka5', '#', defHeight, 5);
menu[1] = new Array();
menu[1][0] = new Menu('fileMenu', 0, 22, 80, defOver, defBack, defBorder);
menu[1][1] = new Item('Linka4', '#', defHeight, 0);
menu[1][2] = new Item('Linka5', '#', defHeight, 0);
menu[1][3] = new Item('Linka6', '#', defHeight, 0);
menu[1][4] = new Item('Linka7', '#', defHeight, 0);
menu[1][5] = new Item('Linka8', '#', defHeight, 0);
menu[2] = new Array();//fantasyflash.ru
menu[2][0] = new Menu('editMenu', 0, 22, 80, defOver, defBack, defBorder);
menu[2][1] = new Item('Linka9', '#', defHeight, 0);
menu[2][2] = new Item('Linka10', '#', defHeight, 0);
menu[2][3] = new Item('Linka11', '#', defHeight, 0);
menu[3] = new Array();
menu[3][0] = new Menu('helpMenu', 0, 22, 80, defOver, defBack, defBorder);
menu[3][1] = new Item('Linka12', '#', defHeight, 0);
menu[3][2] = new Item('Linka13', '#', defHeight, 0);
menu[3][3] = new Item('Linka14', '#', defHeight, 0);
menu[4] = new Array();//osw
menu[4][0] = new Menu('reopenMenu', 0, 22, 80, defOver, defBack, defBorder);
menu[4][1] = new Item('Linka15', '#', defHeight, 0);
menu[4][2] = new Item('Linka16', '#', defHeight, 0);
menu[4][3] = new Item('Linka17', '#', defHeight, 0);
menu[5] = new Array();
menu[5][0] = new Menu('fileMenu', 0, 22, 80, defOver, defBack, defBorder);
menu[5][1] = new Item('Linka4', '#', defHeight, 0);
menu[5][2] = new Item('Linka5', '#', defHeight, 0);
menu[5][3] = new Item('Linka6', '#', defHeight, 0);
menu[5][4] = new Item('Linka7', '#', defHeight, 0);
menu[5][5] = new Item('Linka8', '#', defHeight, 0);
newRoot = startDL('rootMenu', 0, 0, '100%', 17, 'hidden', '#666699', null, 100, '5');
newRoot += startDL('rootMenu1', 5, 0, 40, 17, 'inherit', '#666699', null, 100, mouseProps(0, 1));
newRoot += '<span class="Item"> Linka 1</span>' + endDL;
newRoot += startDL('rootMenu2', 55, 0, 40, 17, 'inherit', '#666699', null, 100, mouseProps(0, 2));
newRoot += '<span class="Item"> Linkа 2</span>' + endDL;
newRoot += startDL('rootMenu3', 105, 0, 40, 17, 'inherit', '#666699', null, 100, mouseProps(0, 3));
newRoot += '<span class="Item"> Linkа 3</span>' + endDL;
newRoot += startDL('rootMenu4', 159, 0, 40, 17, 'inherit', '#666699', null, 100, mouseProps(0, 4));
newRoot += '<span class="Item"> Linkа 4</span>' + endDL;
newRoot += startDL('rootMenu5', 210, 0, 40, 17, 'inherit', '#666699', null, 100, mouseProps(0, 5));
newRoot += '<span class="Item"> Linkа 5</span>' + endDL;
newRoot += endDL;//osw
writeMenus(newRoot, '>');
if (isNS4) document.captureEvents(Event.CLICK);
document.onclick = clickHandle;
function clickHandle(evt) {
if (isNS4) document.routeEvent(evt);
hideAllBut(0);
}
eval(docObj + menu[0][0].id + styObj + '.visibility = "visible"');
function moveRoot() {
rM = eval(docObj + menu[0][0].id + styObj);
if (parseInt(rM.top) < 40) rM.top = 40;
else rM.top = 0;
}</script>
</body>
</html>
- Подпись автора
Не ищи, а то найдешь...