Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post

    Switching images

    Hi, I wish to make it so that when an image is rolled over it is displayed below, in another div but bigger. I would like it so that many images can do this.

    e.g.

    Image 1 Image 2 Image 3 Image 4 Image 5



    Large Image 3


    Here is the current code which I adapted from another code which uses hot spots. I am not an advanced user of JavaScript but I understand it at a basic level.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Fenton Gallery</title>
    <!--<LINK rel="stylesheet" href="stylesheet.css" />-->
    <SCRIPT language = "Javascript1.2">
    Image1 = new Image();
    Image1.src = "images/switcher/image1.jpg";
    Image2 = new Image();
    Image2.src = "images/switcher/image2.jpg";
    
    function setimage(pos,num) {
    	if (num==1) {
    		document.images(pos).src="images/switcher/image1.jpg"
    		}	
    	if (num==2) {
    		document.images(pos).src="images/switcher/image2.jpg"
    		}
    }		
    </SCRIPT>
    </head>
    <body>
    <div class="header">
      <div class="links" align="center">
        <!--#include file = "includes/menu.asp"-->
      </div>
      <div class="style-switcher">
        <!--#include file = "includes/style-switcher-links.asp"-->
      </div>
    </div>
    <div class="navbar" align="center">
      <!--#include file = "includes/navbar_content.asp"-->
    </div>
    <div class="main_text"> <a href="#" onmouseover="setimage(0,2)"><img id="img1" src="images/switcher/image1.jpg" class="download-images"/></a> <img src="images/switcher/image2.jpg" width="200"/> </div>
    </body>
    </html>
    Please help and if you change the code so that it works then please explain what you did so I can learn from this.

  • #2
    Regular Coder
    Join Date
    Nov 2007
    Location
    Chicago
    Posts
    134
    Thanks
    2
    Thanked 9 Times in 9 Posts
    There's probably more than a few things wrong that your script. For starters:
    Code:
    <SCRIPT language = "Javascript1.2">
    "Javascript1.2" isn't a valid language value. "javascript" is.

    But before you get any advice on the code, you've got to use your context clues.

    1) Do you get any errors? What do they say? When do they appear?
    2) Have you attempted to debug the code? Does any part of it work?

    We're not here to simply write the code for you and then explain why it works. We're here to help *you* figure it out.

    PS - This should have been posted in the JavaScript forum.

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,475
    Thanks
    6
    Thanked 980 Times in 953 Posts
    Quote Originally Posted by arthurakay View Post
    There's probably more than a few things wrong that your script. For starters:
    Code:
    <SCRIPT language = "Javascript1.2">
    "Javascript1.2" isn't a valid language value. "javascript" is.
    In fact, the language attribute itself isnít valid HTML (anymore). You should use <script type="text/javascript">.

  • #4
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,667
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Quote Originally Posted by martynball View Post
    Hi, I wish to make it so that when an image is rolled over it is displayed below, in another div but bigger. I would like it so that many images can do this.

    e.g.

    Image 1 Image 2 Image 3 Image 4 Image 5



    Large Image 3
    Please help and if you change the code so that it works then please explain what you did so I can learn from this.
    Hello martynball,
    If your interested in a CSS solution I have an example you could follow...
    Have a look at http://nopeople.com/CSS/disjointed_r...bum/index.html

    You can google "disjointed rollover" for more examples.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #5
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    The original script worked. But cheers

    And I will have a look at that website you linked me to, cheers

  • #6
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    The example which you gave me to look at is not really ideal. It just uses two images and when rolled over the image is re-sized.

    I really need it to replace a image already existing, without defining every single image in the javascript. Because there would be a lot of images to reference which would make one long script.

    Edit:
    In Dreamweaver there is pre-written code to do a image swap. I can make it swap the image and do everything I want it to do, but the image it replaces it with is the full size, and I don't really want to resize all the images. So I was wondering if I could make the script replace the image with the content of the image rolled over instead?

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <link rel="stylesheet" href="../stylesheet.css" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript">
    <!--
    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }
    
    function MM_swapImgRestore() { //v3.0
      var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }
    
    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }
    
    function MM_swapImage() { //v3.0
      var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
       if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }
    //-->
    </script>
    </head>
    <body onload="MM_preloadImages('../images/gal/image9.jpg')">
    <table width="200" border="0" cellspacing="0" cellpadding="0">
          <td>
          <div class="download" align="center">
          <img src="http://th03.deviantart.net/fs45/300W/f/2009/134/e/5/greenorange__by_simoendli.jpg" class="download-images" id="Image1" onmouseover="MM_swapImage('placeholder','','Image1',1)" onmouseout="MM_swapImgRestore()"/>
          <a class="none-special" href="http://th03.deviantart.net/fs45/300W/f/2009/134/e/5/greenorange__by_simoendli.jpg" title="Image 1"  target="_blank">Download</a>      </div>
      </td>
          <td>  
          <div class="download" align="center">
          <img src="http://th06.deviantart.net/fs42/300W/f/2009/161/7/5/7554e260b7871229fa188c6800c2a3db.jpg" class="download-images"/>
          <a class="none-special" href="http://th06.deviantart.net/fs42/300W/f/2009/161/7/5/7554e260b7871229fa188c6800c2a3db.jpg" target="_blank">Download</a>
          </div>
      </td>
          <td>  
          <div class="download" align="center">
          <img src="http://th01.deviantart.net/fs44/300W/f/2009/135/0/4/04d5aec6a8e28717d9002d4eb4ca2483.jpg" class="download-images"/>
          <a class="none-special" href="http://th01.deviantart.net/fs44/300W/f/2009/135/0/4/04d5aec6a8e28717d9002d4eb4ca2483.jpg" target="_blank">Download</a>
          </div>
          <td>
          <div class="download" align="center">
          <img src="http://th09.deviantart.net/fs51/300W/i/2009/269/6/0/A_New_Day_by_Dr4kon.jpg" class="download-images"/>
          <a class="none-special" href="http://th09.deviantart.net/fs51/300W/i/2009/269/6/0/A_New_Day_by_Dr4kon.jpg" target="_blank">Download</a>
          </div>
          </td>
                <td>
          <div class="download" align="center">
          <img src="http://fc05.deviantart.com/fs42/f/2009/121/d/d/dd2ca70e1f0524c1a55db5a3e74041c9.jpg" class="download-images"/>
          <a class="none-special" href="http://fc05.deviantart.com/fs42/f/2009/121/d/d/dd2ca70e1f0524c1a55db5a3e74041c9.jpg" target="_blank">Download</a>
          </div>
          </td>
          </tr>
      </table>
      <img src="../images/preview.png" id="placeholder"/>
    </body>
    </html>
    Last edited by martynball; 11-10-2009 at 11:49 AM.


  •  

    Posting Permissions

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