How to Embed a Rollover on a GIF

How to Embed a Rollover on a GIF thumbnail
The rollover effect happens when a mouse pointer hovers on top of an image.

When visiting sites, you may notice changing navigation buttons at the touch of a mouse pointer. This effect is called the rollover effect. It can by achieved by manipulating your image, or GIF, file through two methods: by embedding a JavaScript code or through the Cascading Style Sheet, or CSS. Each method works the same way, but is implemented differently. Both are widely used, but users with JavaScript turned off on their browsers may not see this effect.

Instructions

  1. Using JavaScript

    • 1

      Create two versions of your GIF file: one version for when the mouse hovers over it, and the other in its normal state.

    • 2

      Insert your GIF on a Web page using the following HTML code:

      <a href="yoursite.com" onMouseOver="gifOver();return true;" onMouseOut="gifOut();return true;" >

      <img name=myimage width=35 height=35 border=0

      src="normal.gif">

      </a>

      Replace "yoursite.com" with the site you want the image to link to, and "normal.gif" with the name of the GIF file you created in its normal state.

    • 3

      Add the JavaScript code to swap out images in the <HEAD> section of your Web page:

      <script language="JavaScript">

      if (document.images) {

      img_on =new Image(); img_on.src ="mouseover.gif";

      img_off=new Image(); img_off.src="normal.gif";

      }

      function gifOver() {

      if (document.images) document.imgName.src=img_on.src;

      }

      function gifOut() {

      if (document.images) document.imgName.src=img_off.src;

      }

      </script>

      Replace "mouseover.gif" with the name of the GIF you created for when the mouse hovers over the image and "normal.gif" with the image in its normal state.

    • 4

      Save the changes to your Web page.

    Using CSS

    • 5

      Create a GIF image in its normal state and append the mouse-over state of the image at the bottom. Both images must be equal in height. For example, if the normal GIF is 35 by 35 pixels, the mouse-over GIF should also be 35 by 35 pixels. In total, the whole image should be 70 pixels high in this example. Save the image.

    • 6

      Insert the GIF in your Web page using the following HTML code:

      <a href="yourwebsite.com" id="rollover">Text Here</a>

      Replace"yourwebsite.com" with the URL where the image points to and "Text Here" with the text you want to appear on top of your GIF image. If you do not want text to appear, you can put a spacer such as " " or place an empty transparent GIF image.

    • 7

      Open Notepad and create a stylesheet with the following code:

      a#rollover{

      background: URL(myimage.gif);

      display:block;

      width: 35px;

      height: 35px;

      }

      a#rollover:hover{

      background-position: 0 -35px;

      }

      Replace "myimage.gif" with the name of your GIF file, and the height and weight with the dimensions of your image. Save it as "rollover.css."

    • 8

      Insert the stylesheet in the <HEAD> section of your Web page using this code:

      <link rel="stylesheet" type="text/css" href="rollover.css" />

    • 9

      Save your Web page.

Related Searches:

References

  • Photo Credit Jupiterimages/Photos.com/Getty Images

Comments

You May Also Like

  • How to Animate GIF Files on PowerPoint

    Microsoft PowerPoint is a tool to create multimedia presentations. Adding GIF files to PowerPoint slides creates interest and provides a focal point...

  • HTML Image Rollover Effects

    An image rollover effect is an important tool in modern Web pages. "e-mail" button with cursor image by Jaroslav Machacek from Fotolia.com

  • How to Float an Image in XHTML

    According to W3 Schools, Extensible Hypertext Markup Language (XHTML) is similar to Hypertext Markup Language (HTML), but has stricter rules. For example,...

  • How to Insert .GIF Files on My Website

    Adding an image to your website can greatly improve its attractiveness for visitors. The most commonly used file format for images on...

  • How to Make a GIF File Web Page

    GIF stands for Graphics Interchange Format. Websites commonly use images in GIF format because they are universally supported and read even in...

  • How to Embed Animated GIFs in Emails

    Adding animated GIF images into your email messages can enhance the look of your email and better promote the message. Animated GIFs...

  • How to Embed Images in HTML Email

    The word "embed" basically means to surround. Hypertext markup language (HTML) uses a collection of signs and symbols to surround text, pictures...

Related Ads

Featured