Forum Moderators: open

Message Too Old, No Replies

Add timeout to onmouseover of onblur

When the mousehover keyboard/focus lost, timeout to hide layer

         

JAB Creations

9:14 pm on Jul 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Below is a working example of changing classes with the onmouseover and onmouseout events.

I want to add a timeout for div.example...so when it (or any of it's children) have no focus or hover states for say five seconds, it changes the class then (instead of instantly).

Here is what I have right now...

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>example</title>
<style type="text/css">
.hideme {
display: none;
}
div.example {
border: #f0f solid 1px;
}
</style>
<script type="text/javascript">
//<![CDATA[
function change(id, newClass)
{
identity=document.getElementById(id);
identity.className=newClass;
}
//]]>
</script>
</head>

<body>

<div><a href="#" onmouseout="change('example', 'example');">mouseover to bring div back</a></div>

<div class="example" id="example" onmouseover="change('example', 'hideme');">
<span>example</span>
</div>

</body>
</html>

JAB Creations

6:43 pm on Jul 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I came up with an alternative way of approaching this though it's instant and the timer doesn't seem to apply.

Here we go...

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>example</title>
<style type="text/css">
.hideme {
display: none;
}
div.example {
border: #f0f solid 1px;
}
</style>
<script type="text/javascript">
//<![CDATA[
function blurchange(id, newClass)
{
myTimeout = window.setTimeout(function() {document.getElementById(id).className=newClass;}, 1400);
}
//]]>
</script>
</head>

<body>

<div><a href="#" blurchange('example', 'hideme');">mouseover to bring div back</a></div>

<div class="example" id="example" onmouseover="change('example', 'hideme');">
<span>example</span>
</div>

</body>
</html>

- John