Question:

What is the rollover effect html code?

by  |  earlier

0 LIKES UnLike

i noticed rollover effects sometimes doesnt work for firefox so can i get the code? i want the one where it shows image1 and when you hover your mouse over it, it changes to image2. nothing fancy just that. also--if there is a code difference between Internet Explorer and firefox, can i get both?

 Tags:

   Report

3 ANSWERS


  1. If this is your image:

    <img src="pic1.jpg" />

    then you can change it by this:

    <img src="pic1.jpg" onmouseover="swap(this,'pic2.jpg')" onmouseout="swap(this,'pic1.jpg')" />

    <script language="JavaScript" type="text/javascript">

    function swap (e,p) { e.src = p; }

    </script>

    As it says in the code it works with JavaScript. There is no way changing a picture by only using HTML.


  2. HTML cant do rollovers, from what I remember.

    You have to use DHTML or Javascript so that it will work in internet explorer and mozilla based browsers like firefox.

  3. People who say rollovers can't be done without java-script always forget about the :hover pseudo class in css which works without javascript. All you have to do is set an image as background and then change it on hover. Set it's container to the size of the image in the css.

    <html>

    <head>

    <title></title>

    <style type="text/css">

    .change { background:url(pic1.jpg) no-repeat; width:100px; height:40px; }

    .change:hover { background:url(pic2.jpg) no-repeat; }

    </style>

    </head>

    <body>

    <div class="change"></div>

    </body>

    </html>

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions