Forum Moderators: open

Message Too Old, No Replies

SetTimeout Issue

Need to delay my JS...params not being passed correctly

         

RhythmAddict

4:04 pm on Jan 18, 2005 (gmt 0)



hey everyone..I have a JS function that is showing layers onMouseOver, and onMouseOut, I'm hiding the layer(s). My problem is I want to delay the onMouseOut event for say, 5 seconds...I have tried using setTimeout, however the 2 params I am passing into the function are "unidentified" if I attempt this method...How can I get around this? code follows, thank you in advance...


<html>
<head>
<title>:::show.hide:::</title>

<script language="JavaScript">
<!--
// Show layer function
function Show(id, visibility) {
obj = document.getElementsByTagName("div");
obj[id].style.visibility = "visible";
}

// Hide layer function
function Hide(id, visibility) {
obj = document.getElementsByTagName("div");
obj[id].style.visibility = "hidden";
}
//-->
</script>

<style type="text/css">
<!--
#sub1Div
{
visibility:hidden;
width:80px;
height:80px;
position:absolute;
left:200px;
top:20px;
border:1px solid #151515;
}
-->
</style>

</head>
<body>
<div id="sub1Div"> sub1</div>
<p>
<a href="#"
onmouseover="Show('sub1Div','visible')"
onmouseout="Hide('sub1Div','hidden')">
showhide.sub1
</a>
</p>


</body>
</html>

StupidScript

6:32 pm on Jan 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So you are attempting:

onmouseout=setTimeout("Hide('sub1Div','hidden')",50000)

?

And in this case 'sub1Div' and 'hidden' are undefined?

Would you please post your timeout code?

Off the top, you may want to initialize a couple of variables onmouseover to make this a little more simple:

onmouseover="thisdiv='sub1Div';hidestate='hidden';Show(thisdiv,'visible')"

onmouseout="hideit=setTimeout('Hide(thisdiv,hidestate)',50000)"

And in your Hide function:

function Hide(div,state) {

clearTimeout(hideit);

etc...

BTW: Welcome to the forums! :)