Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamically find the pixel height of the <a> tag 1

Status
Not open for further replies.

ClulessChris

IS-IT--Management
Jan 27, 2003
890
GB
I’m using the following code (From to show and hide navigation menus.
Would it be possible (and if so how) to dynamically find the pixel height of the <a> tag the function is called from?
Html:
Code:
<a href="#" onMouseOver="hideAll(); showLayer('layer1'); stopTime()" onMouseOut="startTime();">menu 1</a><br><br>
		             <div id="layer1">
			              <a href="[URL unfurl="true"]www.somepage.com"[/URL] onMouseOver="stopTime();" onMouseOut="startTime();">Link 1</a><br><br>        
			              <a href=" [URL unfurl="true"]www.somepage.com"[/URL] onMouseOver="stopTime();" onMouseOut="startTime();">Link 2</a><br><br>
			              <a href=" [URL unfurl="true"]www.somepage.com[/URL] onMouseOver="stopTime();" onMouseOut="startTime();">Link 3</a><br><br>
		            </div>
{/code]
Script:
[Code]
    //Define global variables

	    var timerID = null;
		var timerOn = false;
		var timecount = 1000;
		var what = null;
		var newbrowser = true;
		var check = false;

    	function init(){
    	
    	//  alert ("Running Init");
          if (document.layers) {
                      //  alert ("Running Netscape 4");
                        layerRef="document.layers";
                        styleSwitch="";
                        visibleVar="show";
			screenSize = window.innerWidth;
			what ="ns4";


          }else if(document.all){
                      //  alert ("Running IE");
                        layerRef="document.all";
                        styleSwitch=".style";
                        visibleVar="visible";
			screenSize = document.body.clientWidth + 18;
			what ="ie";

		  }else if(document.getElementById){
                      //  alert ("Running Netscape 6");
                        layerRef="document.getElementByID";
                        styleSwitch=".style";
                        visibleVar="visible";
			what="moz";
		  
		  }else{
		  	//alert("Older than 4.0 browser.");
			what="none";
			newbrowser = false;
		  }
		  
 
		//window.status='status bar text to go here';
		check = true;
		
			if(document.getElementsByTagName){ 
	          matchColumns();			 
	     	} 

  	 	}

	// Turns the layers on and off
        function showLayer(layerName){
        	if(check){
        		if (what =="none"){
        			return;
        			}
	        	else if (what == "moz"){
        			document.getElementById(layerName).style.visibility="visible";
        			}
        		else{
                  eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"');
                  }
		 }
        	else {// alert ("Please wait for the page to finish loading.");
        		return;}
		}

        function hideLayer(layerName){
        	if(check){
        		if (what =="none"){
        			return;
        			}
        		else if (what == "moz"){
        			document.getElementById(layerName).style.visibility="hidden";
        			}
        		else{
                  eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"');
				}
        
        	}
        	else {// alert ("Please wait for the page to finish loading.");
        		return;}
        }

		// function hideAll adapted by Chris Hellings to pick up all layers
		function hideAll() {
    			var divNum = 1;
    			while (divEl = document.getElementById('layer' + divNum)) {
        		hideLayer(divEl.id);
        		divNum++;
    				}
			}


		function startTime() {
	        if (timerOn == false) {
                timerID=setTimeout( "hideAll()" , timecount);
                timerOn = true;

	        }

		}


		function stopTime() {
	        if (timerOn) {
    	        clearTimeout(timerID);
                timerID = null;
                timerOn = false;
	        }
		}

Never knock on Death's door: ring the bell and run away! Death really hates that!
 
Hi Chris, height and width on an anchor tag (<a>) will only work in IE as your not really supposed to add dimensions to the tag itself. Why dont you pop your links inside a div and get the dimensions of that instead?

Nick

where would we be without rhetorical questions...
 
nickdel,
the idea was to pick up the px hight of the link (in a vertical list of links). to align the pop up menu to this anchor that launched it.
art you suggesting a div for each link?

Thanks once again for your input.

Never knock on Death's door: ring the bell and run away! Death really hates that!
 
Yup, you can assign mouse over/click events to a div so you can use them.

Nick

where would we be without rhetorical questions...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top