You are not logged in.

  • Login

1

Thursday, July 15th 2010, 10:36pm

Div-Layer soll sich nach x Sekunden schließen

Hallo allerseits!

Ich hab hier ein kleines JS-Script bei dem ich nicht weiterkomme. Ich öffne über das onload-Attribut im Body ein herkömliches Layer-Popup:

Cascading Style Sheets

1
2
3
4
5
6
7
8
9
10
11
12
13
#popup {
position: absolute;
visibility: hidden;
width: 427px;
height: 182px;
left: 220px;
top: -100px;
background-color: #ccc;
border: 1px solid #000;
padding: 10px;
background:url('images/popup_background.jpg'); 
background-repeat:repeat-x;
}


JavaScript Code

1
2
3
4
5
6
function setVisible(obj)
{
	obj = document.getElementById(obj);
	obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
	obj = document.setTimeout('obj.style.visibility == "hidden"',5000);
}


HTML Code

1
2
3
<div id="popup">
Inhalt
</div>


Öffnen tut sich das Popup, nur, dass es sich nach ein paar Sekunden wieder von alleine schließt - das will noch nicht so recht....
Was JS angeht, bin ich ehrlich gesagt blutiger Anfänger... darum würde ich mich um Unterstützung sehr freuen :)

//////// EDIT
Hat sich geklärt! :)

This post has been edited 1 times, last edit by "allaniay" (Jul 15th 2010, 11:21pm)


2

Friday, July 16th 2010, 8:53am

kannst du die Lösung bitte noch posten?
ich nehme an, es lag nur an der falsch Zuweisung?
obj.style.visibility == "hidden" statt obj.style.visibility = "hidden"

ich würde statt mit der visibility empfehlen mit display zu arbeiten. Da visibility das Objekt nicht wirklich entfernt. Man kann also auf keine Elemente dahinter klicken.

JavaScript Code

1
2
3
4
5
6
function setblock(obj)
{
	obj = document.getElementById(obj);
	obj.style.display = (obj.style.display != 'none') ? 'none' : 'block';
	obj = document.setTimeout('obj.style.display = "none"; ',5000);
}

Social bookmarks