• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1207
  • Last Modified:

Hover over text, thumbnail image appears

I'm putting some wallpapers on my website that people can download by clicking on a text link and the appropriate size.
What I would like to do is when the mouse hovers over the text link, a thumbnail of the wallpaper will appear.

I think i've seen this before possibly at QXL.com.

Can anyone help?
0
matreece
Asked:
matreece
  • 6
  • 6
  • 2
1 Solution
 
justinbilligCommented:
<htmL>
<body>
<a href="#" id="Wallpaper1.jpg" onmouseover="InsertImg( this.id );" onmouseout="InsertImg( 'none' );">Wallpaper1</a>
<br><br>

<img src="holder.jpg" height="1" width="1" id="idWallpaper">

<script language="javascript">
function InsertImg( strImage )
{

      // Get a reference to the img
        var objImage = document.getElementById( "idWallpaper" );

      // Do we clear the img?
       if( strImage != "none" )
       {
            // No
            objImage.src = strImage;
            objImage.style.height = 200;
            objImage.style.width = 200;
       }
       else
       {
            objImage.src = "holder.jpg";
            objImage.style.height = 1;
            objImage.style.width = 1;
        }
}
</script>
</body>
</html>



0
 
justinbilligCommented:
change this line

<a href="#" id="Wallpaper1.jpg" onmouseover="InsertImg( this.id );" onmouseout="InsertImg( 'none' );">Wallpaper1</a>

to this

<a href="#" id="Wallpaper1.jpg" onmouseover="InsertImg( this.id );" onmouseout="InsertImg( 'none' );" onclick="(return false);">Wallpaper1</a>
0
 
matreeceAuthor Commented:
Thats almost what im after although ideally i wanted it to appear next to the cursor. I guess it would be in a layer that follows the cursor when hovering over the link text.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
hemebondCommented:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
      <head>
            <title>Q_21156215</title>
            <!--[if IE]><script type="text/javascript">var ie = true;</script><![endif]-->
            <style type="text/css">
                  dl      {position:relative;}
                  dt      {position:absolute;}
            </style>
      </head>
      <body>
            <dl>
                  <dt><img src="/images/1.jpg" alt=""></dt>
                  <dd><a href="">800x600</a></dd>
                  <dd><a href="">1024x768</a></dd>
            </dl>
      </body>
      <script type="text/javascript">
            var thumbnail = null;
            var list = document.getElementsByTagName("dd");
            for(var i = 0; i < list.length; i++)
            {
                  if(window.ie)
                  {
                        list[i].onmouseover = show_thumbnail;
                        list[i].onmouseout = hide_thumbnail;
                        list[i].onmousemove = move_thumbnail;
                  }
                  else
                  {
                        list[i].addEventListener('mouseover',show_thumbnail,true);
                        list[i].addEventListener('mouseout',hide_thumbnail,true);
                        list[i].addEventListener('mousemove',move_thumbnail,true);
                  }
                  list[i].parentNode.getElementsByTagName('dt')[0].style.display = 'none';
            }

            function show_thumbnail(e)
            {
                  thumbnail = (window.ie) ? this.parentNode.getElementsByTagName('dt')[0] : e.currentTarget.parentNode.getElementsByTagName('dt')[0];
                  thumbnail.style.display = '';
            }

            function hide_thumbnail(e)
            {
                  thumbnail.style.display = 'none';
            }

            function move_thumbnail(e)
            {
                  if(window.ie)
                  {
                        thumbnail.style.top = window.event.clientY + "px";
                        thumbnail.style.left = window.event.clientX + "px";
                  }
                  else
                  {
                        thumbnail.style.top = e.clientY + "px";
                        thumbnail.style.left = e.clientX + "px";
                  }
            }
      </script>
</html>
0
 
hemebondCommented:
Hmm. Remove

dt     {position:absolute;}

and add

list[i].parentNode.getElementsByTagName('dt')[0].style.position = 'absolute';

below

list[i].parentNode.getElementsByTagName('dt')[0].style.display = 'none';
0
 
matreeceAuthor Commented:
This is exactly what i'm after.
Just a couple of problems though:
I'm getting an error saying "'thumbnail.style' is null or not an object"
also
The thumbnail doesn't sit next to the cursor and if i add a couple more links underneath the thumbnail drops down further.
Is it something to do with the first line of code (the bit that says '<!--[if IE]')?

Many thanks for your help
0
 
hemebondCommented:
That <!--[if IE]> is just for Internet Explorer. Other browsers will ignore it, but IE will create that script section that sets a variable so I can hack around IE's rubbish support.

Is this error you're getting only in Internet Explorer? Because it seems to work fine for me, but the debugger in IE isn't working for me, so I can't check anything. Have you used the code exactly as it is here? If not, can you link to the page you've used it in please.
0
 
matreeceAuthor Commented:
This is how my code looks below.
You'll notice when rolling over the bottom links the thumbnail moves further away from the cursor.
And im still getting that error.
Your help is most appreciated.

--------------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
     <head>
          <title>Q_21156215</title>
  <!--[if IE]><script type="text/javascript">var ie = true;</script><![endif]-->
             <style type="text/css">
               dl     {position:relative;}
          </style>
     </head>
     <body>
          <dl>
               <dt><img src="image1.jpg" width="100" height="100" alt=""></dt>
               <dd><a href="#">800x600</a></dd>
               <dd><a href="#">1024x768</a></dd>
          </dl>
              <dl>
               <dt><img src="image2.jpg" width="100" height="100"></dt>
               <dd><a href="#">800x600</a></dd>
               <dd><a href="#">1024x768</a></dd>
          </dl>
                            <dl>
               <dt><img src="image3.jpg" width="100" height="100"></dt>
               <dd><a href="#">800x600</a></dd>
               <dd><a href="#">1024x768</a></dd>
          </dl>
     </body>
     <script type="text/javascript">
          var thumbnail = null;
          var list = document.getElementsByTagName("dd");
          for(var i = 0; i < list.length; i++)
          {
               if(window.ie)
               {
                    list[i].onmouseover = show_thumbnail;
                    list[i].onmouseout = hide_thumbnail;
                    list[i].onmousemove = move_thumbnail;
               }
               else
               {
                    list[i].addEventListener('mouseover',show_thumbnail,true);
                    list[i].addEventListener('mouseout',hide_thumbnail,true);
                    list[i].addEventListener('mousemove',move_thumbnail,true);
               }
               list[i].parentNode.getElementsByTagName('dt')[0].style.display = 'none';
                     list[i].parentNode.getElementsByTagName('dt')[0].style.position = 'absolute';
          }

          function show_thumbnail(e)
          {
               thumbnail = (window.ie) ? this.parentNode.getElementsByTagName('dt')[0] : e.currentTarget.parentNode.getElementsByTagName('dt')[0];
               thumbnail.style.display = '';
          }

          function hide_thumbnail(e)
          {
               thumbnail.style.display = 'none';
          }

          function move_thumbnail(e)
          {
               if(window.ie)
               {
                    thumbnail.style.top = window.event.clientY + "px";
                    thumbnail.style.left = window.event.clientX + "px";
               }
               else
               {
                    thumbnail.style.top = e.clientY + "px";
                    thumbnail.style.left = e.clientX + "px";
               }
          }
     </script>
</html>
0
 
hemebondCommented:
I going to need a line number for the error. I still can't break it.

Btw, change the last code block to this:

thumbnail.style.top = e.layerY + "px";
thumbnail.style.left = e.layerX + "px";
0
 
matreeceAuthor Commented:
Ok, heres the new code.
The error is Line 63 Character 21 'thumbnail.style' is null or not an object.

-------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
     <head>
          <title>Q_21156215</title>
  <!--[if IE]><script type="text/javascript">var ie = true;</script><![endif]-->
             <style type="text/css">
               dl     {position:relative;}
          </style>
     </head>
     <body>
          <dl>
               <dt><img src="images/arcadiaInShipyard41024.jpg" width="100" height="100" alt=""></dt>
               <dd><a href="wallpaperPopArcadiaAtSeaSmall.htm">800x600</a></dd>
               <dd><a href="wallpaperPopArcadiaAtSeaLarge.htm">1024x768</a></dd>
          </dl>
              <dl>
               <dt><img src="images/arcadiaInElba1024.jpg" width="100" height="100"></dt>
               <dd><a href="wallpaperPopArcadiaAtSeaSmall.htm">800x600</a></dd>
               <dd><a href="wallpaperPopArcadiaAtSeaLarge.htm">1024x768</a></dd>
          </dl>
                            <dl>
               <dt><img src="images/arcadiaInElba1024.jpg" width="100" height="100"></dt>
               <dd><a href="wallpaperPopArcadiaAtSeaSmall.htm">800x600</a></dd>
               <dd><a href="wallpaperPopArcadiaAtSeaLarge.htm">1024x768</a></dd>
          </dl>
     </body>
     <script type="text/javascript">
          var thumbnail = null;
          var list = document.getElementsByTagName("dd");
          for(var i = 0; i < list.length; i++)
          {
               if(window.ie)
               {
                    list[i].onmouseover = show_thumbnail;
                    list[i].onmouseout = hide_thumbnail;
                    list[i].onmousemove = move_thumbnail;
               }
               else
               {
                    list[i].addEventListener('mouseover',show_thumbnail,true);
                    list[i].addEventListener('mouseout',hide_thumbnail,true);
                    list[i].addEventListener('mousemove',move_thumbnail,true);
               }
               list[i].parentNode.getElementsByTagName('dt')[0].style.display = 'none';
                     list[i].parentNode.getElementsByTagName('dt')[0].style.position = 'absolute';
          }

          function show_thumbnail(e)
          {
               thumbnail = (window.ie) ? this.parentNode.getElementsByTagName('dt')[0] : e.currentTarget.parentNode.getElementsByTagName('dt')[0];
               thumbnail.style.display = '';
          }

          function hide_thumbnail(e)
          {
               thumbnail.style.display = 'none';
          }

          function move_thumbnail(e)
          {
               if(window.ie)
               {
                    thumbnail.style.top = window.event.clientY + "px";
                    thumbnail.style.left = window.event.clientX + "px";
               }
               else
               {
                    thumbnail.style.top = e.layerY + "px";
          thumbnail.style.left = e.layerX + "px";
               }
          }
     </script>
</html>
0
 
hemebondCommented:
Stupid freakin Internet Explorer. It was calling the move function before it called the over function, so it didn't actually have an object to move.

if(window.ie)
{
      if(!thumbnail) return; // stupid freakin IE
      thumbnail.style.top = window.event.clientY + "px";
      thumbnail.style.left = window.event.clientX + "px";
}
0
 
matreeceAuthor Commented:
Sorry to be a pain - the error has gone which is now fine.
But when i hover over the top link the thumbnail appears slightly to the left of the cursor but when i hover over the bottom two links the thumbnails seem to fall further down the page away from the cursor.
i've included my new code below.
Do you have any idea why it does that?

---------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
     <head>
          <title>Q_21156215</title>
  <!--[if IE]><script type="text/javascript">var ie = true;</script><![endif]-->
             <style type="text/css">
               dl     {position:relative;}
          </style>
     </head>
     <body>
          <dl>
               <dt><img src="image1.jpg" width="100" height="100" alt=""></dt>
               <dd><a href="#">800x600</a></dd>
               <dd><a href="#">1024x768</a></dd>
          </dl>
              <dl>
               <dt><img src="image2.jpg" width="100" height="100"></dt>
               <dd><a href="#">800x600</a></dd>
               <dd><a href="#">1024x768</a></dd>
          </dl>
                            <dl>
               <dt><img src="image3.jpg" width="100" height="100"></dt>
               <dd><a href="#">800x600</a></dd>
               <dd><a href="#">1024x768</a></dd>
          </dl>
     </body>
     <script type="text/javascript">
          var thumbnail = null;
          var list = document.getElementsByTagName("dd");
          for(var i = 0; i < list.length; i++)
          {
               if(window.ie)
               {
                    list[i].onmouseover = show_thumbnail;
                    list[i].onmouseout = hide_thumbnail;
                    list[i].onmousemove = move_thumbnail;
               }
               else
               {
                    list[i].addEventListener('mouseover',show_thumbnail,true);
                    list[i].addEventListener('mouseout',hide_thumbnail,true);
                    list[i].addEventListener('mousemove',move_thumbnail,true);
               }
               list[i].parentNode.getElementsByTagName('dt')[0].style.display = 'none';
                     list[i].parentNode.getElementsByTagName('dt')[0].style.position = 'absolute';
          }

          function show_thumbnail(e)
          {
               thumbnail = (window.ie) ? this.parentNode.getElementsByTagName('dt')[0] : e.currentTarget.parentNode.getElementsByTagName('dt')[0];
               thumbnail.style.display = '';
          }

          function hide_thumbnail(e)
          {
               thumbnail.style.display = 'none';
          }

          function move_thumbnail(e)
          {
               if(window.ie)
               {
                      if(!thumbnail) return;
                      thumbnail.style.top = window.event.clientY + "px";
               thumbnail.style.left = window.event.clientX + "px";
               }
               else
               {
                    thumbnail.style.top = e.layerY + "px";
          thumbnail.style.left = e.layerX + "px";
               }
          }
     </script>
</html>
0
 
hemebondCommented:
if(window.ie)
{
      if(!thumbnail) return;
      thumbnail.style.top = window.event.y + "px";
      thumbnail.style.left = window.event.x + "px";
}
0
 
matreeceAuthor Commented:
Many thanks.
Works perfectly.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 6
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now