Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Putting a timed delay on toggle visible/invisible
Old 09-20-2008, 06:54 PM Putting a timed delay on toggle visible/invisible
Skilled Talker

Posts: 81
Trades: 0
Hi

I wish to toggle visible/invisible the content of a div, when another div is hovered. However, I want the return to visibility to be delayed. I have the following code:
Code:
<script language="javascript" type="text/javascript">
function toggleDisplay(id, action) { 
var el = document.getElementById(id); 
if (el != undefined) { 
if(action == 'visible' || action == 'hidden') { 
el.style.visibility = action; 
if(action =='visible'){ 
setTimeout('toggleDisplay("test","visible")', 2000); 
} 
} else { 
el.style.display = action; 
} 
} 
}
</script>

<div id="test">
This should vanish when text 'hover' is hovered. I would like it to reappear when 'hover' is no
longer hovered, but with a small timed delay
</div>

<div onmouseover="toggleDisplay('test', 'hidden');" onmouseout="toggleDisplay('test', 'visible');">
hover
</div>
But I can't get the time delay on mouseout. I can use a similar code to make something appear, and then vanish again after a timed delay. But I can't get it to happen this way round! Can you see what I should be doing?

Many thanks

Tony
__________________

Please login or register to view this content. Registration is FREE

Last edited by soon; 09-20-2008 at 06:57 PM.. Reason: forgot to ask for email notification
soon is offline
Reply With Quote
View Public Profile Visit soon's homepage!
 
 
Register now for full access!
Old 09-21-2008, 12:23 AM Re: Putting a timed delay on toggle visible/invisible
nyef's Avatar
Ultra Talker

Posts: 265
Name: Lucas
Trades: 0
Change the function to this:
Code:
function toggleDisplay(id, action) { 
var el = document.getElementById(id); 
if (el != undefined) { 
if(action == 'visible' || action == 'hidden') { 
if(action =='visible'){ 
setTimeout("document.getElementById('"+id+"').style.visibility='visible';", 2000); 
} 
else el.style.visibility = action; 
} else { 
el.style.display = action; 
} 
} 
}
__________________
~nyef

Please login or register to view this content. Registration is FREE
nyef is offline
Reply With Quote
View Public Profile Visit nyef's homepage!
 
Old 09-21-2008, 11:56 AM Re: Putting a timed delay on toggle visible/invisible
Skilled Talker

Posts: 81
Trades: 0
Mega thanks. That works fine.


Best wishes

Tony
__________________

Please login or register to view this content. Registration is FREE
soon is offline
Reply With Quote
View Public Profile Visit soon's homepage!
 
Reply     « Reply to Putting a timed delay on toggle visible/invisible
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.36469 seconds with 12 queries