Results 1 to 6 of 6

Thread: help with dynamic menu

  1. #1
    Join Date
    Apr 2007
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help with dynamic menu

    Hi Everyone,

    I'm hoping someone can help me with this problem. What I am trying to do is have 2 different images appear before and after the text that appears via a javascript function.

    Here is my code:



    HTML Code:
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    #mail
    {
      display: block;
      float: left;
      display: inline;
      width: 50px;
      height: 50px;
      background: url("../images/menu/blackrolloverbutton.gif") no-repeat 0 0;
    
    }
    
    #mail:hover
    { 
      background-position: 0 -50px;
    }
    
    #mail span
    {
      display: none;
      
    }
    
    #blog
    {
      display: block;
      float: left;
      display: inline;
      width: 50px;
      height: 50px;
      background: url("../images/menu/bluerolloverbutton.gif") no-repeat 0 0;
    
    }
    
    #blog:hover
    { 
      background-position: 0 -50px;
    }
    
    #blog span
    {
      display: none;
      
    }
    
    #tabledescription{
    	font-family: Arial, Helvetica, sans-serif;
    	font-size: 18px;
    	color: #990033;
    	text-decoration: underline;
    
    }
    
    
    </style>
    <script type="text/javascript">
    
    var baseopacity=0
    
    function showtext(thetext){
    if (!document.getElementById)
    return
    textcontainerobj=document.getElementById("tabledescription")
    browserdetect=textcontainerobj.filters? "ie" : typeof textcontainerobj.style.MozOpacity=="string"? "mozilla" : ""
    instantset(baseopacity)
    document.getElementById("tabledescription").innerHTML=thetext
    highlighting=setInterval("gradualfade(textcontainerobj)",50)
    }
    
    function hidetext(){
    cleartimer()
    instantset(baseopacity)
    }
    
    function instantset(degree){
    if (browserdetect=="mozilla")
    textcontainerobj.style.MozOpacity=degree/100
    else if (browserdetect=="ie")
    textcontainerobj.filters.alpha.opacity=degree
    else if (document.getElementById && baseopacity==0)
    document.getElementById("tabledescription").innerHTML=""
    }
    
    function cleartimer(){
    if (window.highlighting) clearInterval(highlighting)
    }
    
    function gradualfade(cur2){
    if (browserdetect=="mozilla" && cur2.style.MozOpacity<1)
    cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.2, 0.99)
    else if (browserdetect=="ie" && cur2.filters.alpha.opacity<100)
    cur2.filters.alpha.opacity+=20
    else if (window.highlighting)
    clearInterval(highlighting)
    }
    
    </script>
    </head>
    
    <body>
    
    
    <table width="252" border="0" cellpadding="0" cellspacing="0">
      <!--DWLayoutTable-->
      <tr> 
        <td width="252" height="55" valign="top">
    	    <a href="http://www.a.com" id="mail" onMouseover="showtext('JavaScript tutorials and scripts!')" onMouseout="hidetext()"></a> 
            <a href="http://www.b.com" id="blog" onMouseover="showtext('300+ free JavaScripts')" onMouseout="hidetext()"></a> 
            <a href="http://www.c.com" id="mail" onMouseover="showtext('Comprehensive JavaScript Reference')" onMouseout="hidetext()"></a> 
            <a href="http://www.d.com" id="blog" onMouseover="showtext('Web coding and development forums!')" onMouseout="hidetext()"></a> 
            <a href="http://www.e" id="mail" onMouseover="showtext('Award winning DHTML and JavaScripts')" onMouseout="hidetext()"></a> 
            </td>
      </tr>
      <tr> 
        <td height="19" align="center" valign="top"><div id="tabledescription">Click buttons above!</div></td>
      </tr>
    </table>
    </body>
    </html>



    So basically I have 5 buttons and when the mouse hovers over a button, text appears below the button.

    For example, when someone hovers over the first button, the following text appears:
    JavaScript tutorials and scripts!

    I just want to have a little icon before and after the above text.

    I've been trying to figure this out for hours! I've tried using the css before and after psuedo styles and also the icon style.

    Nothing works.

    Please help.

    Thanks.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Please post a link to the page on your site that contains the problematic script so we can check it out.
    Jeremy | jfein.net

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I'm not wild about your coding, but if it works for you that's fine with me for the time being. Given that, if the icon(s) you want to show will be the same regardless of the text displayed:

    Code:
    function showtext(thetext){
    if (!document.getElementById)
    return
    textcontainerobj=document.getElementById("tabledescription")
    browserdetect=textcontainerobj.filters? "ie" : typeof textcontainerobj.style.MozOpacity=="string"? "mozilla" : ""
    instantset(baseopacity)
    document.getElementById("tabledescription").innerHTML='<img src="icon.gif"> ' + thetext + ' <img src="icon.gif">';
    highlighting=setInterval("gradualfade(textcontainerobj)",50)
    }
    The src attributes for the image tags in the above may be whatever you like.

    Now, if the images you will be using will vary depending upon the text displayed, you can probably just use your function as is, but do this in the markup area where it is called:

    Code:
    <a href="http://www.a.com" id="mail" 
    onmouseover="showtext('<img src=\'icon.gif\'> JavaScript tutorials and scripts! <img src=\'icon.gif\'>')" 
    onmouseout="hidetext()"></a>
    Once again, the src attributes for the image tags may be whatever you like.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Apr 2007
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks John.

    I will try your solution and see if it works.

  5. #5
    Join Date
    Apr 2007
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Hi again

    So I tried the above solution and it works great in Firefox! so thank you so much.

    However, it does not work in internet explorer. I don't know why it is not working. The text does not show up when you hover over the buttons. This has nothing to do with adding the icons on each side of the text...because it didn't work before I added the icons.

    Does anyone know?

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    This syntax isn't correct:

    Code:
    textcontainerobj.filters.alpha.opacity=degree
    Even if it were, there is no filter on the textcontainerobj.

    It gets worse though because if you use the right syntax and have the alpha filter already on the textcontainerobj it will look bad in IE 7. IE 7 doesn't do filters on text very well.

    With that said, here's a version that works:

    Code:
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    #mail
    {
      display: block;
      float: left;
      display: inline;
      width: 50px;
      height: 50px;
      background: url("../images/menu/blackrolloverbutton.gif") no-repeat 0 0;
    
    }
    
    #mail:hover
    { 
      background-position: 0 -50px;
    }
    
    #mail span
    {
      display: none;
      
    }
    
    #blog
    {
      display: block;
      float: left;
      display: inline;
      width: 50px;
      height: 50px;
      background: url("../images/menu/bluerolloverbutton.gif") no-repeat 0 0;
    
    }
    
    #blog:hover
    { 
      background-position: 0 -50px;
    }
    
    #blog span
    {
      display: none;
      
    }
    
    #tabledescription{
    	font-family: Arial, Helvetica, sans-serif;
    	font-size: 18px;
    	color: #990033;
    	text-decoration: underline;
    filter:progid:DXImageTransform.Microsoft.alpha(opacity=100);
    zoom:100%;
    }
    
    
    </style>
    <script type="text/javascript">
    
    var baseopacity=0
    
    function showtext(thetext){
    if (!document.getElementById)
    return
    textcontainerobj=document.getElementById("tabledescription")
    browserdetect=textcontainerobj.filters? "ie" : typeof textcontainerobj.style.MozOpacity=="string"? "mozilla" : ""
    instantset(baseopacity)
    document.getElementById("tabledescription").innerHTML=thetext
    highlighting=setInterval("gradualfade(textcontainerobj)",50)
    }
    
    function hidetext(){
    cleartimer()
    instantset(baseopacity)
    }
    
    function instantset(degree){
    if (browserdetect=="mozilla")
    textcontainerobj.style.MozOpacity=degree/100
    else if (browserdetect=="ie")
    textcontainerobj.filters[0].opacity=degree
    else if (document.getElementById && baseopacity==0)
    document.getElementById("tabledescription").innerHTML=""
    }
    
    function cleartimer(){
    if (window.highlighting) clearInterval(highlighting)
    }
    
    function gradualfade(cur2){
    if (browserdetect=="mozilla" && cur2.style.MozOpacity<1)
    cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.2, 0.99)
    else if (browserdetect=="ie" && cur2.filters[0].opacity<100)
    cur2.filters[0].opacity+=20
    else if (window.highlighting)
    clearInterval(highlighting)
    }
    
    </script>
    </head>
    
    <body>
    
    
    <table width="252" border="0" cellpadding="0" cellspacing="0">
      <!--DWLayoutTable-->
      <tr> 
        <td width="252" height="55" valign="top">
    	    <a href="http://www.a.com" id="mail" onMouseover="showtext('JavaScript tutorials and scripts!')" onMouseout="hidetext()"></a> 
            <a href="http://www.b.com" id="blog" onMouseover="showtext('300+ free JavaScripts')" onMouseout="hidetext()"></a> 
            <a href="http://www.c.com" id="mail" onMouseover="showtext('Comprehensive JavaScript Reference')" onMouseout="hidetext()"></a> 
            <a href="http://www.d.com" id="blog" onMouseover="showtext('Web coding and development forums!')" onMouseout="hidetext()"></a> 
            <a href="http://www.e" id="mail" onMouseover="showtext('Award winning DHTML and JavaScripts')" onMouseout="hidetext()"></a> 
            </td>
      </tr>
      <tr> 
        <td height="19" align="center" valign="top"><div id="tabledescription">Click buttons above!</div></td>
      </tr>
    </table>
    </body>
    </html>
    What I would suggest though is, instead of fading the text in and out, place an image or a division with a solid background over the text and fade it out and in.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •