+ Reply to Thread
Results 1 to 5 of 5

Thread: JavaScript:Tutorial, MouseOver Image Change

  1. #1
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101

    JavaScript:Tutorial, MouseOver Image Change

    Introduction:-
    In this tutorial I will show you how to change the image when the user puts the cursor over an image and then change it back when the user puts the cursor away from the image.

    Solution:-
    Make These Two Functions Between The <head> tags:-

    Code:
    <SCRIPT language="JavaScript">
    
    if (document.images)
     {
         img1on= new Image(100,100);
         img1on.src="img2.jpg";  
    
         img1off= new Image(100,100);
         img1off.src="img1.jpg";
     }
    
    function change(imgName)
     {
       if (document.images)
          {
             imgOn=eval(imgName + "on.src");
             document[imgName].src= imgOn;
          }
     }
    
    function changeback(imgName)
     {
       if (document.images)
          {
            imgOff=eval(imgName + "off.src");
            document[imgName].src= imgOff;
          }
     }
    
    </SCRIPT>
    And Make This code between the <body> Tags:-

    Code:
    <A onMouseover="change('img1')" onMouseout="changeback('img1')">
    <IMG SRC="img1.jpg" name="img1" width="100" height="100"></A>
    Save your work and add these 2 images into your directory to see the effect




    Explanation:-
    You think it is needed? I think its self explanatory. But if you have any problems.. just ask

    A Preview:-


    Conclusion:-
    As Always Feedback is welcome and the full source is attached!!
    Attached Files Attached Files
    Last edited by TcM; 12-03-2006 at 10:30 AM.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    sahar88 is offline Newbie
    Join Date
    Feb 2007
    Posts
    5
    Rep Power
    0
    it's cool ... thank you...

  4. #3
    cvirus is offline Newbie
    Join Date
    Oct 2007
    Posts
    2
    Rep Power
    0

    Thumbs up Very Good

    Very good tutorial, nice for a web site.

  5. #4
    cryptokyle's Avatar
    cryptokyle is offline Newbie
    Join Date
    May 2009
    Location
    Singapore
    Posts
    11
    Rep Power
    0

    Re: JavaScript:Tutorial, MouseOver Image Change

    Code:
    if (document.images)
     {
         img1on= new Image(100,100);
         img1on.src="img2.jpg";  
    
         img1off= new Image(100,100);
         img1off.src="img1.jpg";
     }
    i need help with understanding this portion of the code.

  6. #5
    Jordan Guest

    Re: JavaScript:Tutorial, MouseOver Image Change

    It is creating a new image that is 100x100 (size) and the src is img2.jpg. Similar to saying:

    HTML Code:
    <img src="img2.jpg" width="100" height="100">

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Similar Threads

  1. Using Listbox to change image in Picturebox!
    By rubbadrools in forum C# Programming
    Replies: 7
    Last Post: 07-19-2011, 06:38 PM
  2. change image with dropdown
    By bfly03 in forum JavaScript and CSS
    Replies: 1
    Last Post: 07-27-2010, 09:10 AM
  3. Mouseover to start javascript slide show
    By gaylo565 in forum JavaScript and CSS
    Replies: 0
    Last Post: 10-15-2009, 12:10 PM
  4. Change image url with dropdown selection
    By Hrimthurs in forum JavaScript and CSS
    Replies: 5
    Last Post: 05-07-2008, 06:45 AM
  5. Change image help
    By wilk3sy in forum JavaScript and CSS
    Replies: 3
    Last Post: 12-19-2007, 03:45 AM

Tags for this Thread

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