www.webdeveloper.com
Results 1 to 2 of 2

Thread: Need information on script to change image when mouse is placed on it?

Hybrid View

  1. #1
    Join Date
    Dec 2013
    Posts
    2

    Need information on script to change image when mouse is placed on it?

    Hello

    I have a website that I have designed small voodoo skulls for I am looking to have it do that when people hoover there mouse over the skills the image changes to an open mouth image and words follow of there mouths.

    I am a complete novice in terms of javascript and would appreciate a starting point from someone with more experience I am not looking for someone to do it for me I am just looking for assitance?

    I have searched the web but they allow seems to require some JS knowledge which I have none of at the moment.

    Any help would be appreciated.

  2. #2
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    255
    Code:
    <!DOCTYPE html>
    <html>
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
        <title>Untitled</title>
        <script type='text/javascript'>
            "use strict";
            
            function chImage(that) {
                var img1 = "car1.jpg", img2 = "car2.jpg"; //replace "car1.jpg" and "car2.jpg" with one of your images
                that.src = (that.src.substring(that.src.lastIndexOf("/") +1) === img1) ? img2 : img1;
                return;
            }
        </script>
    </head>
    <body>
        <div><img src="car1.jpg" alt="car image" onmouseover="chImage(this)" onmouseout="chImage(this)" /></div>
    </body>
    </html>

Thread Information

Users Browsing this Thread

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

Posting Permissions

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



Recent Articles