If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2

Thread: Got a Question

  1. #1
    Junior Member Dietrich's Avatar
    Join Date
    Nov 2003
    Member #
    How can you make a link so it changes to a different pictures when the curser goes over it?

    Anyone know how to do that or where to get a modifyable scrpt for it?


  3. #2
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Not from USA
    Member #
    2784 times
    That particular example was done in Macromedia Dreamweaver, which comes with its own image preload/rollover Javascript. If you're unfamiliar with Javascript, it may be the way to go.

    Having said that, you usually need three things to do this:

    1. Image swapping code (see below):
    <script language="JavaScript" 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;
    function MM_swapImgRestore() { //v3.0
      var i,x,a=document.MM_sr; 
    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];
      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; 
       if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;
       if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    preloadImages is called in the body tag using the onLoad property, whereby you put in all of the mouseover (cursor over) images The mouseout (cursor off) images don't need to be preloaded since these were the ones that were loaded by default.

    mm_swapImage swaps the presented image with its mouseover image (assuming it can findObj, or find the object--the mouseover image--that exists).

    mm_swapImgRestore swaps the presented image with its mouseout image (assuming it can findObj, or find the object--the mouseover image--that exists).

    2. The Body tag needs to have the images preloaded onLoad (onLoad events are events that occur when the normal page is loaded; you want your images preloaded AFTER the page is loaded in order to prevent your user seeing a completely blank page.)

    <body bgcolor="#000033" background="images/dkblue_pixel_bg.jpg" 
    text="#FFFFFF" link="#FFFFFF" vlink="#3366FF" alink="#00FFCC"

    As you can see, all of the images for mouseover effects are being preloaded.

    3. A hyperlink containing the onmouseover and onmouseout effects.
    <a href="discovery_traces.htm" 
    <img src="images/btns/hpg_btn2.jpg" alt="" name="hpg_btn2" 
    width="220" height="30" border="0" id="hpg_btn2" />
    You don't really need to understand all of this code; the important parts are the name of the graphic (since this is the graphic that will be changing when the cursor hovers over the image); the onmouseover function called (MM_swapImage); and the onmouseout function called (mm_swapImgRestore()).

    Important Note: the line breaks wouldn't actually appear in the code in most places where I put them; I've just put these in to avoid breaking up the WDF layout. See the original code for that site for the exact formatting.

    That's about all there is to it.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
All times are GMT -6. The time now is 04:17 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: