943,553 Members | Top Members by Rank

Ad:
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Jan 19th, 2009
1

Re: Javascript onHover effect ?

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
The reason why I didn't go into details was that I haven't been using much JavaScript lately so it's a little rusty.

But make a function like this:

HTML and CSS Syntax (Toggle Plain Text)
  1. function onoff (id,onoff)
  2. { if (!GetElementByID(id)) return false;
  3. GetElementById (id).visibility = onoff;
  4. return true;
  5. }

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)
  1. <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)
  1. GetElementById (id).innerHTML = text;
  2. GetElementById (id).style.top = top;
  3. 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)
  1. <script type="text/JavaScript">
  2. <?php
  3. echo <<<end
  4. <!-- (Some older browsers and "3C validation requires this)
  5. var baby = "$text1";
  6. var doll = "$text2";
  7. var puppy = "$text3";
  8. var teddy = "$text4";
  9. // -->
  10. </script>
  11.  
  12. end;
  13. ?>

...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)
  1. function changeStackOrder(layer)
  2. {
  3. document.getElementById("img1").style.zIndex=layer;
  4. }

"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.
Reputation Points: 16
Solved Threads: 9
Junior Poster
ingeva is offline Offline
106 posts
since Jul 2008
Jan 19th, 2009
0

Re: Javascript onHover effect ?

ingeva thanyou so much
i'l add to your reputation, that was a really good response.
Thankyou for taking the time
Reputation Points: 12
Solved Threads: 16
Posting Whiz
Designer_101 is offline Offline
314 posts
since Jul 2007
Oct 1st, 2009
0

CSS Hover effect ?

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
HTML and CSS Syntax (Toggle Plain Text)
  1. <td width="53">
  2. <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" />
  3. <span><img src="images/popoutTest_1.jpg" width="200" height="272" />
  4. <br />Image Description</span></a>
  5. </div>
  6. </td>

And the css
HTML and CSS Syntax (Toggle Plain Text)
  1. /*Credits: Dynamic Drive CSS Library */
  2. /*URL: http://www.dynamicdrive.com/style/ */
  3.  
  4. .thumbnail
  5. {
  6. position: relative;
  7. z-index: 0;
  8. padding-left:40;
  9. padding-right:40;
  10. }
  11.  
  12. .thumbnail:hover
  13. {
  14. background-color: transparent;
  15. z-index: 50;
  16. text-decoration: none;
  17. }
  18.  
  19. .thumbnail span /*CSS for enlarged image*/
  20. {
  21. position: absolute;
  22. background-color: lightyellow;
  23. padding: 5px;
  24. left: -1000px;
  25. border: 1px dashed gray;
  26. visibility: hidden;
  27. color: black;
  28. text-decoration: none;
  29. }
  30.  
  31. .thumbnail span img /*CSS for enlarged image*/
  32. {
  33. border-width: 0;
  34. padding: 2px;
  35. }
  36.  
  37. .thumbnail:hover span /*CSS for enlarged image on hover*/
  38. {
  39. visibility: visible;
  40. left: 60px; /*position where enlarged image should offset horizontally */
  41. top: 10px;
  42. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pmcd9 is offline Offline
5 posts
since Sep 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in HTML and CSS Forum Timeline: Form Inside Table Getting Messed Up
Next Thread in HTML and CSS Forum Timeline: CSS mozilla problems





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC