| | |
Javascript onHover effect ?
Please support our HTML and CSS advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2008
Posts: 101
Reputation:
Solved Threads: 9
•
•
•
•
Thankyou ingeva
can anyone explain any problems with using onHover events to change the visibility of a div through css visibility of a div ?
If not, then il use that method
But make a function like this:
HTML and CSS Syntax (Toggle Plain Text)
function onoff (id,onoff) { if (!GetElementByID(id)) return false; GetElementById (id).visibility = onoff; return true; }
If "onoff" is "hidden" the element will still take up place but in your case it must be in a different layer than the main page, so it doesn't matter. The opposite of "hidden" is "visible".
Of course, you need something like this HTML/JavaScript code for the element:
HTML and CSS Syntax (Toggle Plain Text)
<div id="element" onmouseover ='onoff("element","visible")' onmouseout ='onoff("element","hidden")'>(to be filled by function)</div>
If you want a text variable to fill the box and set the position ov the element, do it like this:
HTML and CSS Syntax (Toggle Plain Text)
GetElementById (id).innerHTML = text; GetElementById (id).style.top = top; GetElementById (id).style.left = left;
Of course you need to define the top and left positions. You can probably find a routine for that also, but this function is very browser dependable so you may have to do some studying.
To define text variables in JavaScript from php, do this:
HTML and CSS Syntax (Toggle Plain Text)
<script type="text/JavaScript"> <?php echo <<<end <!-- (Some older browsers and "3C validation requires this) var baby = "$text1"; var doll = "$text2"; var puppy = "$text3"; var teddy = "$text4"; // --> </script> end; ?>
...and you can call the function specifying one of the texts: baby, doll, puppy or teddy.
Since I am multilingual, I sometimes put different language texts in different php include files, so all I need to change for a different language is the name of the include file. But this is outside the scope of this thread ....

I recommend the W3schools for help here. Their javascript reference is quite readable, although you need to learn the basics of the language before you get too intimate with the semantics.
I don't know if I can leave an URL here, but if you search for "JavaScript Tutorial" you'll find a link to the W3schhols. W3C is THE authority on web programming standards.
AFTERTHOUGHT:
Since the "visibility" settings can differ between browsers, it might be an idea to use this instead:
HTML and CSS Syntax (Toggle Plain Text)
function changeStackOrder(layer) { document.getElementById("img1").style.zIndex=layer; }
"layer" is the layer (or stack) number you want to place the element in. If it's higher than the main page, it will show, and if it's lower (and the main page has an opaque background) it won't. I believe this will work for all browsers that can interpret JavaScript.
Last edited by ingeva; Jan 19th, 2009 at 4:26 pm.
Please help with a similar hover problem I am having.
I have written a CSS hover effect and it works perfectly for me, but I want to add the ability for the hover to sense the edge of the browser and adjust itself to remain inside the browser window at all times much like the hover effect works on this messageboard.
Can this be accomplished with CSS or do I have to resort to JavaScript? In either case I don't know how to go about it and would appreciate the help of the more learned members of this board.
Thank you.
Here is the code I have written...
The HTML
And the css
I have written a CSS hover effect and it works perfectly for me, but I want to add the ability for the hover to sense the edge of the browser and adjust itself to remain inside the browser window at all times much like the hover effect works on this messageboard.
Can this be accomplished with CSS or do I have to resort to JavaScript? In either case I don't know how to go about it and would appreciate the help of the more learned members of this board.
Thank you.
Here is the code I have written...
The HTML
HTML and CSS Syntax (Toggle Plain Text)
<td width="53"> <div align="center"><a class="thumbnail" href="http://www.yahoo.com" target="_blank"><img src="images/thumbTest_1.jpg" width="50px" height="68px" border="0" /> <span><img src="images/popoutTest_1.jpg" width="200" height="272" /> <br />Image Description</span></a> </div> </td>
And the css
HTML and CSS Syntax (Toggle Plain Text)
/*Credits: Dynamic Drive CSS Library */ /*URL: http://www.dynamicdrive.com/style/ */ .thumbnail { position: relative; z-index: 0; padding-left:40; padding-right:40; } .thumbnail:hover { background-color: transparent; z-index: 50; text-decoration: none; } .thumbnail span /*CSS for enlarged image*/ { position: absolute; background-color: lightyellow; padding: 5px; left: -1000px; border: 1px dashed gray; visibility: hidden; color: black; text-decoration: none; } .thumbnail span img /*CSS for enlarged image*/ { border-width: 0; padding: 2px; } .thumbnail:hover span /*CSS for enlarged image on hover*/ { visibility: visible; left: 60px; /*position where enlarged image should offset horizontally */ top: 10px; }
![]() |
Other Threads in the HTML and CSS Forum
- Previous Thread: Form Inside Table Getting Messed Up
- Next Thread: CSS mozilla problems
| Thread Tools | Search this Thread |
appointments asp background backgroundcolor beta browser bug calendar cart cgi code codeinjection corporateidentity css design development displayimageinsteadofflash dreamweaver emailmarketing epilepsy explorer firefox flash form format google griefers hackers hitcounter hover html ide ie7 ie8 iframe image images internet internetexplorer intranet iphone javascript jpeg layout macbook maps marketshare microsoft mozilla multimedia navigationbars news offshoreoutsourcingcompany opacity opera optimization pnginie6 positioning problem scroll seo shopping studio swf swf. textcolor timecolor titletags url urlseparatedwords visual visualization web webdevelopment webform website windows7






