webForumDet fria alternativet

layer problem

3 svar · 169 visningar · startad av OveRRidE

OveRRidEMedlem sedan feb. 200112 078 inlägg
#1

Jag kan inte få lagret att visas..
hur gör jag?

Kod i div.html:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title>Untitled</title>
<script language="javascript" src="js/script.js"></script>
</head>

<body>

<a href="#" onMouseUp="show('layer1')" onfocus="this.blur();">Klicka mig!</a><br>
<a href="#" onMouseUp="hide('layer1')" onfocus="this.blur();">Klicka mig2!</a>

<div id="layer1" style="position: absolute; visibility: hidden; left:100; top:100; width:400; height:150; z-index: 20">
Denna texten skall enbart synas när länken är aktiv.
</div>

</body>
</html>

Kod i script.js:

	<!--
	
	var isNav, isIE
	var coll = ""
	var styleObj = ""

	if (parseInt(navigator.appVersion) >= 4)
	{
		if (navigator.appName == "Netscape") {
			isNav = true
		} else {
			isIE = true
			coll = "all."
			styleObj = ".style"
		}
	}
	
	function getObject(obj) {
		var theObj		
		if (typeof obj == "string")	 {			
			theObj = eval("document." + coll + obj + styleObj)
		} else {
			theObj = obj
		}
		return theObj
	}
	
	function shiftTo(obj, x, y) {	
		var theObj = getObject(obj)		
		if (isNav) {
			theObj.moveTo(x, y)			
		} else{
			theObj.pixelLeft = x
			theObj.pixelTop = y
		}
	}
	
	function setZIndex(obj, zOrder) {
		var theObj = getObject(obj)
		theObj.zIndex = zOrder
	}
	
	function show(obj) {	
		var theObj = getObject(obj)
		hideAll()
		theObj.visibility = "visible"
	}
	
	function hide(obj) {
		var theObj = getObject(obj)
		theObj.visibility = "hidden"
	}
	
	function hideAll()
	{
		hide('layer1')
		hide('layer2')
		hide('layer3')
		hide('layer4')
		hide('layer5')
		hide('layer6')
		hide('layer7')
		hide('layer8')
		hide('layer9')
		hide('layer10')
		hide('layer11')
		hide('layer12')
		hide('layer13')
		hide('layer14')
		hide('layer15')
		hide('layer16')
		hide('layer17')
		hide('layer18')
		hide('layer19')
		hide('layer20')
	}
	//-->

Pliz someone.. jag får det inte o funka :(

------------------
SELECT * FROM existence WHERE sex = 'female' AND age > '18' AND age < '25' OR name = 'Sandra Bullock' ORDER BY breastsize

JojoxxMedlem sedan juni 20004 308 inlägg
#2

Problemet är att du i functionen hideAll() försöker gömma lager som inte finns. Lägg till en funktion som ser ut så här;

function isObject(obj){
	if (document.all) {
		if(document.all[obj]){ return true; }
	} else if (document.layers){
		if(document.layers[obj]){ return true; }
	} else if (document.getElementById){
		if(document.getElementById(obj)){ return true; }
	}
}

och ändra sedan i functionen hideAll() så att det står;

if (isObject('layer1')){ hide('layer1'); }
if (isObject('layer2')){ hide('layer2'); }
if (isObject('layer3')){ hide('layer3'); }
...osv...

------------------
/ J

OveRRidEMedlem sedan feb. 200112 078 inlägg
#3

jo det funkar, men jag har problem med zIndex:en nu..

om jag först tar fram layer1 och sedan layer2, och sedam försöker ta fram layer1 igen, så visas den inte. Den hamnar väl bakom layer2 då antar jag..

Hur får jag den som klickas att alltid hamn högst upp?

kod för script.js:

	<!--	
	
	// Global Variables
	var isNav, isIE
	var coll = ""
	var styleObj = ""

	if (parseInt(navigator.appVersion) >= 4)
	{
		if (navigator.appName == "Netscape") {
			isNav = true
		} else {
			isIE = true
			coll = "all."
			styleObj = ".style"
		}
	}
	
	// Convert an objectname to a object reference
	function getObject(obj) {
		var theObj		
		if (typeof obj == "string")	 {			
			theObj = eval("document." + coll + obj + styleObj)
		} else {
			theObj = obj
		}
		return theObj
	}
	
	// Put an object on a specific co-ordinate
	function shiftTo(obj, x, y) {	
		var theObj = getObject(obj)		
		if (isNav) {
			theObj.moveTo(x, y)			
		} else{
			theObj.pixelLeft = x
			theObj.pixelTop = y
		}
	}
	
	// Set Z-order for object
	function setZIndex(obj, zOrder) {
		var theObj = getObject(obj)
		theObj.zIndex = zOrder
	}
	
	// Show object
	function show(obj) {	
		var theObj = getObject(obj)
		hideAll()
		theObj.visibility = "visible"
	}
	
	// Hide object
	function hide(obj) {
		var theObj = getObject(obj)
		theObj.visibility = "hidden"
	}
	
	function hideAll()
	{
		if (isObject('tjanst')){ hide('tjanst'); }
		if (isObject('kontakt')){ hide('kontakt'); }
		if (isObject('case')){ hide('case'); }
		if (isObject('start')){ hide('start'); }
		
	}
	//-->
	
	function isObject(obj){
	if (document.all) {
	if(document.all[obj]){ return true; }
	} else if (document.layers){
	if(document.layers[obj]){ return true; }
	} else if (document.getElementById){
	if(document.getElementById(obj)){ return true; }
	}
	}

	//-->

Länk:

<a href="#" onMouseUp="show('layer1');"><img src="gfx/h_tjanster.gif" border="0"></a>

Help..
------------------
SELECT * FROM existence WHERE sex = 'female' AND age > '18' AND age < '25' OR name = 'Sandra Bullock' ORDER BY breastsize

[Redigerat av OveRRidE den 06 jul 2001]

OveRRidEMedlem sedan feb. 200112 078 inlägg
#4

Ups!

Jag kom på varför det inte funkade *dunka hammare i huvet*

function hideAll()
	{
		if (isObject('layer1')){ hide('layer1'); }
		if (isObject('layer2')){ hide('layer2'); }
		if (isObject('layer3')){ hide('layer3'); }
		if (isObject('layer4')){ hide('layer4'); }
		
	}

sådär! de skall ju heta rätt med :)

------------------
SELECT * FROM existence WHERE sex = 'female' AND age > '18' AND age < '25' OR name = 'Sandra Bullock' ORDER BY breastsize

130 ms totalt · 3 externa anrop · v20260731065814-full.30151723
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
128 ms — hämta tråd, inlägg och bilagor (db)