www.webdeveloper.com
Results 1 to 12 of 12

Thread: Looking for code: img that changes img on mouseover

  1. #1
    Join Date
    Aug 2012
    Posts
    21

    Looking for code: img that changes img on mouseover

    hello!

    i used to use:

    <A HREF="http://www.cnn.com"
    onMouseOver="document.pic1.src='main2.jpg'"
    onMouseOut="document.pic1.src='main.jpg'">
    <IMG SRC="main.jpg" BORDER=0 NAME="pic1">
    </a>


    im confused its been awhile...

    all i want is a img to change to diff img on mouse over as a link as well!

    any thoughts?

  2. #2
    Join Date
    Aug 2012
    Location
    Belgium
    Posts
    66

    resolved

    I personnaly use jquery.

    <a href="http://www.cnn.com" id="main">
    <img src="first.jpg" border=0 name="pic1" id="mainpic">
    </a>

    <script type="text/javascript">
    $('#main').hover(function(){
    $('#mainpic').attr('src','second.jpg');
    }, function(){
    $('#mainpic').attr('src','first.jpg');
    })
    </script>

  3. #3
    Join Date
    Aug 2012
    Location
    Belgium
    Posts
    66

    resolved

    ...

  4. #4
    Join Date
    Aug 2012
    Posts
    1
    Quote Originally Posted by Oppression View Post
    hello!

    i used to use:

    <A HREF="http://www.cnn.com"
    onMouseOver="document.pic1.src='main2.jpg'"
    onMouseOut="document.pic1.src='main.jpg'">
    <IMG SRC="main.jpg" BORDER=0 NAME="pic1">
    </a>


    im confused its been awhile...

    all i want is a img to change to diff img on mouse over as a link as well!

    any thoughts?
    Try do this

    <img src="/image.jpg" width="150" height="100" name="image_name"
    onmouseover="image_name.width='300';image_name.height='200';"
    onmouseout="image_name.width='150';image_name.height='100';" />

  5. #5
    Join Date
    Aug 2012
    Posts
    21
    that makes sense.

    and thanks!

    I will try that!

  6. #6
    Join Date
    May 2005
    Location
    Gold Coast (MS)
    Posts
    2,213
    Simple:

    Code:
    <img src="image1.gif" onmouseover="this.src='image2.gif'" onmouseout="this.src='image1.gif'" style="width: XXXpx; height: YYYpx;" alt="" />
    Example

  7. #7
    Join Date
    Aug 2012
    Location
    Belgium
    Posts
    66
    For so far I know, best practices recomend placing js code at bottom of page and not within your html.

    c.f. point 5:
    http://net.tutsplus.com/tutorials/ja...for-beginners/

  8. #8
    Join Date
    Aug 2012
    Posts
    21
    thanks a ton you guys!

    i hope one day i can help others with their problems too. its been way too long since i did any scripting / coding etc

    i highly would recomend these forums.. everyone seems so patient and helpful, i love it.

  9. #9
    Join Date
    Aug 2012
    Posts
    21
    i tried the jqueury script

    it gave me a 'to help protect your security I.E has prevented scripts etc etc etc pop up' at the top..

    i'd rather not use scripts id rather use css or html, as i heard many people will not activate the script. for security purposes. i need raw html. / css.

  10. #10
    Join Date
    Aug 2012
    Posts
    21
    <img src="image.jpg" width="32" height="33" name="test"
    onmouseover="test.width='32';test.height='33';"
    onmouseout="test.width='150';test.height='33';" />


    simply changes the size..... i have 2 images 1 for reg 1 for hover (link)

  11. #11
    Join Date
    Aug 2012
    Posts
    21
    Quote Originally Posted by Major Payne View Post
    Simple:

    Code:
    <img src="image1.gif" onmouseover="this.src='image2.gif'" onmouseout="this.src='image1.gif'" style="width: XXXpx; height: YYYpx;" alt="" />
    Example
    this works!

  12. #12
    Join Date
    May 2005
    Location
    Gold Coast (MS)
    Posts
    2,213
    If you just want CSS:

    Basic image swap using CSS

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