Visualizzazione dei risultati da 1 a 3 su 3

Discussione: Menu a tendina

  1. #1
    Utente di HTML.it
    Registrato dal
    Nov 2007
    Messaggi
    473

    Menu a tendina

    Ciao a tutti e da un po di giorno che sto impazzendo a fare un menu!!

    Dunque ho un menu ad albero che funziona, ho scaricato il codice da accordion, dentro al menu ad albero ho diverse voci dove passando il mouse sopra compare la sottocategoria, percio dentro il menu ad albero ho un menu a tendina....

    per il menu a tendina ho scaricato qst esempio

    http://www.dhtmlgoodies.com/scripts/...-out-menu.html

    io purtroppo ho la necessita di avere piu sottocategorie per ogni voce del menu ad albero!
    il problema si presenta solo su explorer!!!!

    ho trovato due file js in questo il menu a tendina non supporta piu di una sottocategoria

    codice:
    
    	var timeBeforeAutoHide = 700;	// Microseconds to wait before auto hiding menu(1000 = 1 second)
    	var slideSpeed_out = 10;	// Steps to move sub menu at a time ( higher = faster)
    	var slideSpeed_in = 10;
    		
    	
    	var slideTimeout_out = 25;	// Microseconds between slide steps ( lower = faster)
    	var slideTimeout_in = 10;	// Microseconds between slide steps ( lower = faster)
    	
    	var showSubOnMouseOver = true;	// false = show sub menu on click, true = show sub menu on mouse over
    	var fixedSubMenuWidth = false;	// Width of sub menu items - A number(width in pixels) or false when width should be dynamic
    	
    	var xOffsetSubMenu = 0; 	// Offset x-position of sub menu items - use negative value if you want the sub menu to overlap main menu
    	
    	var slideDirection = 'right';	// Slide to left or right ?
    	
    	/* Don't change anything below here */
    	
    	var activeSubMenuId = false;
    	var activeMainMenuItem = false;
    	var currentZIndex = 1000;		
    	var autoHideTimer = 0;
    	var submenuObjArray = new Array();
    	var okToSlideInSub = new Array();
    	var subPositioned = new Array();
    	
    
    	function stopAutoHide()
    	{
    		autoHideTimer = -1;
    	}
    	
    	function initAutoHide()
    	{
    		autoHideTimer = 0;
    		if(autoHideTimer>=0)autoHide();
    	}
    	
    	function autoHide()
    	{
    		
    		if(autoHideTimer>timeBeforeAutoHide)
    		{
    			
    			if(activeMainMenuItem){
    				activeMainMenuItem.className='';
    				activeMainMenuItem = false;
    			}
    			
    			if(activeSubMenuId){
    				var obj = document.getElementById('subMenuDiv' + activeSubMenuId);
    				showSub();
    			}
    		}else{
    			if(autoHideTimer>=0){
    				autoHideTimer+=50;
    				setTimeout('autoHide()',50);
    			}
    		}
    	}	
    	
    	function getTopPos(inputObj)
    	{		
    	  var returnValue = inputObj.offsetTop;
    	  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
    	  return returnValue;
    	}
    	
    	function getLeftPos(inputObj)
    	{
    	  var returnValue = inputObj.offsetLeft;
    	  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
    	  return returnValue;
    	}
    	
    	function showSub()
    	{
    		var subObj = false;
    		if(this && this.tagName){
    			var numericId = this.parentNode.id.replace(/[^0-9]/g,'');
    			okToSlideInSub[numericId] = false;
    			var subObj = document.getElementById('subMenuDiv' + numericId);
    			if(activeMainMenuItem)activeMainMenuItem.className='';
    			if(subObj){
    				if(!subPositioned[numericId]){
    					if(slideDirection=='right'){
    						subObj.style.left = getLeftPos(submenuObjArray[numericId]['parentDiv']) + submenuObjArray[numericId]['parentDiv'].offsetWidth + xOffsetSubMenu + 'px';
    					}else{
    						subObj.style.left = getLeftPos(submenuObjArray[numericId]['parentDiv']) + xOffsetSubMenu + 'px';
    						
    					}
    					submenuObjArray[numericId]['left'] = subObj.style.left.replace(/[^0-9]/g,'');
    					subObj.style.top = getTopPos(submenuObjArray[numericId]['parentDiv']) + 'px';
    					subPositioned[numericId] = true;
    				}				
    				subObj.style.visibility = 'visible';
    				subObj.style.zIndex = currentZIndex;
    				currentZIndex++;	
    				this.className='activeMainMenuItem';
    				activeMainMenuItem = this;
    			}
    		}else{
    			var numericId = activeSubMenuId;
    		}
    		if(activeSubMenuId && (numericId!=activeSubMenuId || !subObj))slideMenu(activeSubMenuId,(slideSpeed_in*-1));
    		if(numericId!=activeSubMenuId && this && subObj){
    			subObj.style.width = '0px';	
    			slideMenu(numericId,slideSpeed_out);
    			activeSubMenuId = numericId;
    		}else{
    			if(numericId!=activeSubMenuId)activeSubMenuId = false;
    		}
    		if(showSubOnMouseOver)stopAutoHide();
    	}
    	
    	function slideMenu(menuIndex,speed){
    		var obj = submenuObjArray[menuIndex]['divObj'];
    		var obj2 = submenuObjArray[menuIndex]['ulObj'];
    		var width = obj.offsetWidth + speed;
    		if(speed<0){
    			if(width<0)width = 0;
    			obj.style.width = width + 'px';
    			if(slideDirection=='left'){
    				obj.style.left = submenuObjArray[menuIndex]['left'] - width + 'px';
    				obj2.style.left = '0px';
    			}else{
    				obj2.style.left = width - submenuObjArray[menuIndex]['width'] + 'px' 
    			}
    			if(width>0 && okToSlideInSub[menuIndex])setTimeout('slideMenu(' + menuIndex + ',' + speed + ')',slideTimeout_in); else{
    				obj.style.visibility = 'hidden';
    				obj.style.width = '0px';
    				if(activeSubMenuId==menuIndex)activeSubMenuId=false;
    			}
    			
    		}else{
    			if(width>submenuObjArray[menuIndex]['width'])width = submenuObjArray[menuIndex]['width'];
    			if(slideDirection=='left'){
    				obj.style.left = submenuObjArray[menuIndex]['left'] - width + 'px';
    				obj2.style.left = '0px';
    			}else{
    				obj2.style.left = width - submenuObjArray[menuIndex]['width'] + 'px' 
    			}		
    			
    			obj.style.width = width + 'px';
    			if(width<submenuObjArray[menuIndex]['width']){
    				setTimeout('slideMenu(' + menuIndex + ',' + speed + ')',slideTimeout_out);
    			}else{
    				okToSlideInSub[menuIndex] = true;
    			}
    		}
    	}
    	function resetPosition()
    	{
    		subPositioned.length = 0;
    	}
    			
    	function initLeftMenu()
    	{
    		var isMSIE = navigator.userAgent.indexOf('MSIE')>=0?true:false;
    		var browserVersion = parseInt(navigator.userAgent.replace(/.*?MSIE ([0-9]+?)[^0-9].*/g,'$1'));
    		if(!browserVersion)browserVersion=1;
    		
    		var menuObj = document.getElementById('dhtmlgoodies_menu');	
    		var mainMenuItemArray = new Array();
    		
    		var mainMenuItem = menuObj.getElementsByTagName('LI')[0];
    		while(mainMenuItem){
    			if(mainMenuItem.tagName && mainMenuItem.tagName.toLowerCase()=='li'){
    				mainMenuItemArray[mainMenuItemArray.length] = mainMenuItem;
    				var aTag = mainMenuItem.getElementsByTagName('A')[0];
    				if(showSubOnMouseOver)
    					aTag.onmouseover = showSub;	
    				else
    					aTag.onclick = showSub;	
    			}
    			mainMenuItem = mainMenuItem.nextSibling;
    		}		
    		
    		var lis = menuObj.getElementsByTagName('A');
    		for(var no=0;no<lis.length;no++){
    			if(!showSubOnMouseOver)lis[no].onmouseover = stopAutoHide;
    			lis[no].onmouseout = initAutoHide;
    			lis[no].onmousemove = stopAutoHide;
    		}
    				
    		for(var no=0;no<mainMenuItemArray.length;no++){
    			var sub = mainMenuItemArray[no].getElementsByTagName('UL')[0];
    			if(sub){
    				mainMenuItemArray[no].id = 'mainMenuItem' + (no+1);
    				var div = document.createElement('DIV');
    				div.className='dhtmlgoodies_subMenu';
    				document.body.appendChild(div);
    				div.appendChild(sub);
    				if(slideDirection=='right'){
    					div.style.left = getLeftPos(mainMenuItemArray[no]) + mainMenuItemArray[no].offsetWidth + xOffsetSubMenu + 'px';
    				}else{
    					div.style.left = getLeftPos(mainMenuItemArray[no]) + xOffsetSubMenu + 'px';
    				}
    				div.style.top = getTopPos(mainMenuItemArray[no]) + 'px';
    				div.id = 'subMenuDiv' + (no+1);
    				sub.id = 'submenuUl' + (no+1);
    				sub.style.position = 'relative';	
    
    				if(navigator.userAgent.indexOf('Opera')>=0){
    					submenuObjArray[no+1] = new Array();
    					submenuObjArray[no+1]['parentDiv'] = mainMenuItemArray[no];
    					submenuObjArray[no+1]['divObj'] = div;
    					submenuObjArray[no+1]['ulObj'] = sub;
    					submenuObjArray[no+1]['width'] = sub.offsetWidth;
    					submenuObjArray[no+1]['left'] = div.style.left.replace(/[^0-9]/g,'');
    				}
    				sub.style.left = 1 - sub.offsetWidth + 'px';	
    				
    				
    				
    				if(browserVersion<7 && isMSIE)div.style.width = '1px';	
    					
    				if(navigator.userAgent.indexOf('Opera')<0){
    					submenuObjArray[no+1] = new Array();
    					submenuObjArray[no+1]['parentDiv'] = mainMenuItemArray[no];
    					submenuObjArray[no+1]['divObj'] = div;
    					submenuObjArray[no+1]['ulObj'] = sub;
    					submenuObjArray[no+1]['width'] = sub.offsetWidth;
    					
    					
    					
    					submenuObjArray[no+1]['left'] = div.style.left.replace(/[^0-9]/g,'');
    					if(fixedSubMenuWidth)submenuObjArray[no+1]['width'] = fixedSubMenuWidth;
    				}	
    
    				if(!document.all)div.style.width = '1px';			
    					
    			}			
    		}
    			
    
    		
    		
    		menuObj.style.visibility = 'visible';
    		
    		window.onresize = resetPosition;
    	}
    	
    	
    	window.onload = initLeftMenu;





    mentre con questo altro js accetta le sottocategorie, pero qnd il menu ad albero è chiuso, si vedono le voci del menu a tendina

    il codice lo trovate nel post successivo perche era troppo lungo


    ricapitolando nel il primo codice perche qnd il menu ad albero è chiuso, le voci del menu a tendina non si vedono e va benissimo, pero non accetta piu di una sottocategoria!!!

    mentre l'altro codice accetta piu sottocategorie e va benissimo, ma qnd il menu ad albero è chiuso, si vedono le voci del menu a tendina...

    ho provato a modificare il secondo codice in modo tale che il menu qnd l'albero è chiuso, non si vedesse, ma non ce stato verso

    sapete aiutarmi!!!!

    oppure sapete altri esempi di menu a tendina che hanno un movimento fluido come questo??

    Grazie!

  2. #2
    Utente di HTML.it
    Registrato dal
    Nov 2007
    Messaggi
    473
    secondo codice js


    codice:
    var MENUDIV_ID = "dhtmlgoodies_menu";
    var SUBMENU_CLASS = 'dhtmlgoodies_subMenu';
    var menuItems;
    var slideSpeed_out = 10;	// Steps to move sub menu at a time ( higher = faster)
    var slideSpeed_in = 10;
    var delayMenuClose = 150;	// Microseconds from mouseout to close of menu
    var slideTimeout_out = 25;	// Microseconds between slide steps ( lower = faster)
    var slideTimeout_in = 10;	// Microseconds between slide steps ( lower = faster)
    var xOffsetSubMenu = 0; 	// Offset x-position of sub menu items - use negative value if you want the sub menu to overlap main menu
    
    /* Don't change anything below here */
    
    var indeces = new Array();
    indeces[0] = 0;
    var isMSIE = navigator.userAgent.indexOf('MSIE')>=0?true:false;
    var browserVersion = parseInt(navigator.userAgent.replace(/.*?MSIE ([0-9]+?)[^0-9].*/g,'$1'));
    if(!browserVersion)browserVersion=1;
    
    function mouseOn(obj) {
    	var mi = findNode(getSearchIdFromObj(obj));
    	if (mi) mi.mouseOn();
    }
    
    function mouseOff(obj) {
    	var mi = findNode(getSearchIdFromObj(obj));
    	if (mi) mi.mouseOff();
    }
    
    function getSearchIdFromObj(obj) {
    	// pull the postfix off the A link or LI tag id and return the menu item ID
    	var objId = obj.id;
    	var idx = objId.indexOf('_');
    	if (idx>=0) {
    		return "MenuItem" + objId.substring(idx);
    	}
    	return null;
    }
    
    function slideChildMenu(aId) {
    	var mi = findNode(aId);
    	if (mi) mi.slideChildMenu();
    }
    
    function findNode(searchId) {
    	var result;
    	for (var no=0;no<menuItems.length;no++) {
    		result = menuItems[no].findNode(searchId);
    		if (result) return result;
    	}
    	return null;
    }
    
    function getNextIndex(lvl) {
    	var result = 0;
    	if (indeces.length<=lvl) {
    		indeces[lvl] = 1;
    	} else {
    		result = indeces[lvl];
    		indeces[lvl]++;
    	}
    	return result;
    }
    
    function MenuItem(divref, ulref, liref, lvlnum, parentref) {
    	this.parent = parentref;
    	this.div = divref;
    	this.ul = ulref;
    	this.width = this.ul.offsetWidth;
    	// this.left = div.style.left.replace(/[^0-9]/g,'');
    	this.li = liref;
    	this.alink = this.li.getElementsByTagName('A')[0];
    	this.lvl = lvlnum;
    	this.idx = getNextIndex(this.lvl);
    	this.children;
    	this.subUL = this.li.getElementsByTagName('UL')[0];
    	this.children;
    	this.isMouseOnMe = false;
    	// note: if !isOpen && !isClosed then I am animating a slide
    	this.isChildMenuOpen = false;
    	this.isChildMenuClosed = true;
    
    	// Constructor
    	// if a node does not have an A tag but it's children do then we need
    	// null out this node's alink field...
    	if (this.alink) {
    		if (this.alink.parentNode!=this.li) this.alink = null;
    	}
    	if (this.subUL) {
    		this.children = new Array();
    		var subLI = this.subUL.getElementsByTagName('LI')[0];
    		while(subLI) {
    			if(subLI.tagName && subLI.tagName.toLowerCase()=='li') {
    				this.children[this.children.length] = new MenuItem(null, this.subUL, subLI, this.lvl + 1, this);
    			}
    			subLI = subLI.nextSibling;
    		}
    	}
    
    	this.getPostfix = function() {
    		return '_' + this.idx + '_' + this.lvl;
    	}
    	
    	this.getId = function() {
    		return "MenuItem" + this.getPostfix();
    	}
    
    	this.hasChildren = function() {
    		return (this.children!=null);
    	}
    
    	this.getTopPos = function() {
    		var origDisp = this.div.style.display;
    		this.div.style.display = "";
    		var obj = this.li;
    		var result = obj.offsetTop;
    		while((obj = obj.offsetParent) != null) result += obj.offsetTop;
    		this.div.style.display = origDisp;
    		return result;
    	}
    
    	this.getLeftPos = function() {
    		var origDisp = this.div.style.display;
    		this.div.style.display = "";
    		var obj = this.li;
    		var result = obj.offsetLeft;
    		while((obj = obj.offsetParent) != null) result += obj.offsetLeft;
    		this.div.style.display = origDisp;
    		return result;
    	}
    
    	this.renderNode = function() {
    		// set node properties
    		this.li.id = "menuItemLI" + this.getPostfix();
    		this.ul.style.position = "relative";
    		if (this.alink) {
    			this.alink.id = "menuItemA" + this.getPostfix();
    			this.alink.onmouseover = function() {mouseOn(this);};
    			this.alink.onmouseout = function() {mouseOff(this);};
    		} else {
    			this.li.onmouseover = function() {mouseOn(this);};
    			this.li.onmouseout = function() {mouseOff(this);};
    		}
    
    		// set sub-menu nodes
    		if (this.hasChildren()) {
    			var mi = this.children[0];
    			var subdiv = document.createElement('DIV');
    			subdiv.className=SUBMENU_CLASS;
    			document.body.appendChild(subdiv);
    			subdiv.id = "menuItemDIV" + mi.getPostfix();
    			this.subUL.id = "menuItemUL" + mi.getPostfix();
    			subdiv.appendChild(this.subUL);
    			subdiv.style.left = this.getLeftPos() + this.width + xOffsetSubMenu + 'px';
    			subdiv.style.top = this.getTopPos() + 'px';
    			subdiv.style.visibility = "hidden";
    			subdiv.style.display = "none";
    			subdiv.style.zindex = "1000";
    			for (var no=0;no<this.children.length;no++) {
    				var mi = this.children[no];
    				mi.div = subdiv;
    				mi.renderNode();
    			}
    		}
    		return this.li;
    	}
    
    	this.findNode = function(searchId) {
    		var result;
    		if (this.getId() == searchId) {
    			result = this;
    		} else {
    			if (this.hasChildren()) {
    				for (var no=0;no<this.children.length;no++) {
    					var mi = this.children[no];
    					result = mi.findNode(searchId);
    					if (result!=null) break;
    				}
    			}
    		}
    		return result;
    	}
    
    	this.mouseOn = function() {
    		this.isMouseOnMe = true;
    		if (this.hasChildren() && this.isChildMenuClosed) {
    			this.initiateChildMenuOpen();
    		}
    	}
    
    	this.mouseOff = function() {
    		this.isMouseOnMe = false;
    		if (this.hasChildren() && !this.isChildMenuClosed) {
    			this.initiateChildMenuClose();
    		} else if (this.parent) {
    			this.parent.mouseOff();
    		}
    	}
    
    	this.isMouseOnChild = function() {
    		if (this.isMouseOnMe) return true;
    		if (this.hasChildren()) {
    			for (var no=0;no<this.children.length;no++) {
    				if (this.children[no].isMouseOnChild()) return true;
    			}
    		}
    		return false;
    	}
    
    	this.initiateChildMenuOpen = function() {
    		this.isChildMenuClosed = false;
    		var childDiv = this.children[0].div;
    		childDiv.style.width = "0px";
    		childDiv.style.visibility = "visible";
    		childDiv.style.display = "";
    		this.slideChildMenu();
    	}
    
    	this.initiateChildMenuClose = function() {
    		this.isChildMenuOpen = false;
    		// we have to wait to close the menu
    		// allow the mouse to navigate over the child menu
    		setTimeout("slideChildMenu('" + this.getId() + "')", delayMenuClose);
    	}
    
    	this.slideChildMenu = function() {
    		var divref = this.children[0].div;
    		var ulref = this.children[0].ul;
    		var maxwidth = this.children[0].width;
    		var nextWidth;
    		if (this.isMouseOnMe  || this.isMouseOnChild()) {
    			nextWidth = divref.offsetWidth + slideSpeed_out;
    			if (nextWidth >= maxwidth) {
    				this.finishOpeningChild(divref, ulref, maxwidth);
    			} else {
    				ulref.style.left = nextWidth - maxwidth + "px";
    				divref.style.width = nextWidth + "px";
    				setTimeout("slideChildMenu('" + this.getId() + "')", slideTimeout_out);
    			}
    		} else {
    			nextWidth = divref.offsetWidth - slideSpeed_in;
    			if (nextWidth <= 0) {
    				this.finishClosingChild(divref, ulref, maxwidth);
    			} else {
    				ulref.style.left = nextWidth - maxwidth + "px";
    				divref.style.width = nextWidth + "px";
    				setTimeout("slideChildMenu('" + this.getId() + "')", slideTimeout_out);
    			}
    		}
    	}
    
    	this.finishOpeningChild = function(divref, ulref, maxwidth) {
    		this.isChildMenuOpen = true;
    		this.isChildMenuClosed = false;
    		ulref.style.left = "0px";
    		divref.style.width = maxwidth + "px";
    	}
    
    	this.finishClosingChild = function(divref, ulref, maxwidth) {
    		this.isChildMenuOpen = false;
    		this.isChildMenuClosed = true;
    		divref.style.visibility = "hidden";
    		divref.style.display = "none";
    		divref.style.width = maxwidth + "px";
    		if (this.parent) this.parent.mouseOff();
    	}
    
    }
    
    function collectMenuNodes(menuObj) {
         if (!menuObj) return null;
    
         var results = new Array();
         var menuUL = menuObj.getElementsByTagName('UL')[0];
         var menuLI = menuUL.getElementsByTagName('LI')[0];
         while(menuLI) {
            if(menuLI.tagName && menuLI.tagName.toLowerCase()=='li') {
                  results[results.length] = new MenuItem(menuObj, menuUL, menuLI, 0, null);
            }
            menuLI = menuLI.nextSibling;
         }
         return results;
    }
    
    function initMenu() {
    	var mainDiv = document.getElementById(MENUDIV_ID);
    	menuItems = collectMenuNodes(mainDiv);
    	if (menuItems) {
    		for (var no=0;no<menuItems.length;no++) {
    			var mi = menuItems[no];
    			mi.renderNode();
    		}
    		mainDiv.style.visibility = 'visible';
    	}
    	// window.onresize = resetPosition;
    }
    
    window.onload = initMenu;

  3. #3
    Utente di HTML.it
    Registrato dal
    Nov 2007
    Messaggi
    473
    aiutooo sto impazzendo non riesco a trovare nulla!!!!

    ho trovato altri menu a tendina pero qnd lo metto dentro a un menu ad albero, qnd chiudo il menu ad albero, sotto si vede anche il menu a tendina, qst succede solo su explorer!!!!

    lo sto odiando sempre di piu!!!!!!


    con firefox funziona perfettamente ma con explorer no!!! sapete aiutarmi???

    io devo m,ettere dentro un div che un menu a tendina che possibilmente non si veda qnd ho il menu ad albero chiuso

    Grazie

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.