A revolving earth (earthani.gif--64x64) Beaverland Net
Net Art
 
Japanese Version (japanv.gif--100x36)

Beaverland Net Art logo (netart2.gif--140x365)

Beaverland Net HTML Made Easy! logo (html02.gif--140x160)

Beaverland Net JavaScript Made Easy! logo (javascrx.gif--140x233)

Beaverland Unlisted Slang logo (slangs2.gif--140x260)

Beaverland Historica logo (histbanr.jpg--140x360)

Beaverland Mythology logo (mythbanr.jpg--140x255)

Beaverland Stries logo (stories.jpg--140x276)

Beaverland Webs & Internet Secrets logo (web100.jpg--140x250)

Beaverland Cleopatra Gallery logo (galleryt.gif--177x275)

Beaverland Ciold War Years logo (coldwrbn.jpg--140x320)


onstore.gif (140x93)

beavbook.gif (120x160)

beavcomp.gif (120x160)

beavmovi.gif (120x160)

beavgift.gif (120x160)

beavtrav.gif (120x160)

music.gif (50x50) Beaverland Music
 
How to reduce an animation-file size
with Javascript
August 25, 2003
 

Move your mouse over her hair band.
To stop, move your mouse
out of her head.

1-pixel-by-1 transparent GIF image (spacer.gif--1 x 1)

 

The above Javascript animation consists of the following two 16-million-color JPEG images.

A blonde pinup with both eyes opened (pinup011.JPg--472x629)
pinup011.jpg (16 million colors) size: 32 KB

A blonde pinup's closed eye (pinup013.jpg--120x120)
pinup013.jpg (16 million colors) size: 3 KB

With Javascript, you can create the same animation without any reduction of its quality. Besides, the file size of both pictures is only 35KB.

Comparison Chart
  GIF animation
with 2 full-size pics
GIF animation
with 1 full-size
& 1 part
GIF animation
with 1 full-size
& 1 part
Javascript
animation
with 1 full-size
& 1 part
No. of Colors 127 127 63 16 millions
File size 138 K bytes 76 K 51 K 35 K
Download time
at 14.4K baud
1 min 42 sec 56 38 20
Download time
at 28.8K baud
52 seconds 28 19 10
Download time
at 56K baud
27 seconds 15 10 6
Download time
over ISDN
12 seconds 7 5 3
page described Blonde Pinup:
transparent Gif
animation quality
How to reduce
an animation-
file size
How to reduce
an animation-
file size
even more
this page

 

The following code creates the above animation:

<table background="../images/pinup011.jpg"
    width="472" height="629"
    border="0" cellpadding="0" cellspacing="0">
<tr><td align="left" valign="top">
<a href="javascript:alert('Sorry, only this message
        will show up when you click this picture');"
  onMouseOver="displayWink()" onMouseOut="stopAnim()">
<img border="0" name="myGal"
    src="../images/spacer.gif"
    alt="1-pixel-by-1 transparent GIF image"
    width="120" height="120"></a>
</td></tr>
</table>

<script language="javascript">
<!---- to hide

var myTimerID=null

 

function displayWink() {
  document.myGal.src="../images/pinup013.jpg"
  myTimerID=setTimeout("displaySpacer()",2000)
  }

function displaySpacer() {
  document.myGal.src="../images/spacer.gif"
  myTimerID=setTimeout("displayWink()",2000)
  }

function stopAnim() {
  clearTimeout(myTimerID)
  document.myGal.src="../images/spacer.gif"
  }

//--->
</script>

 

myGal

The green square in the above is defined as document.myGal.src in Javascript so that your browser can place any picture at this particular place as the above code instructs.

A blonde pinup's closed eye (pinup013.jpg--120x120) document.myGal.src="../images/pinup013.jpg"

The above instruction means “move the picture at right to the green square”.

At present, you see spacer.gif at this particular place of the top presentation. Because it is a bloated transparent GIF image, you cannot see it. Instead, you see the girl’s face that shows itself through this transparent image.

When you move your mouse over this green square, the event handler (onMouseOver) will invoke the Javascript function (displayWink()), which will place the above picture into the green square so that the girl can close her eye.

The Javascript engine waits for 2,000 milliseconds or 2 seconds, then it invokes another function (displaySpacer()), which will place spacer.gif so that you can see her face with both eyes opened through the transparent image.

The Javascript engine waits another 2 seconds, and then invokes the function (displayWink()).

In reality, this will loop forever until you move your mouse out of the green square.

When you do this, the event handler (onMouseOut) will invoke the Javascript function (stopAnim()), which will stop the timing mechanism and place spacer.gif so that you see her both eyes open whenever your mouse gets out of this green saquare.

 

For more information, please visit the following links:

 

Related Links





Rate article:
Excellent Good Neutral Poor Worst

Your Name:
Your Email Address:
Comments:


  Comments
 
I don’t want to use a TABLE tag. Do you know that the table tag is deprecated? Is there any way to do the same animation as above, using CSS?

    - Russ Goodsman


I don’t think the table tag is deprecated. I’ve checked all the elements at W3C (World Wide Web Consortium).

Anyway, your point is taken. If you can do it with CSS, then just do it. That is what the W3C staff say.

In any case, I think I can do it with the CSS (Cascading Style Sheet) specification. I will do the above presentation using CSS in the following page: Animation Presentation with CSS.

If you don’t know what “deprecated” means, please click the above link to find it out.

    - Akira

 
 
Copyright Akira Kato
About this author:
  • Educated both in Canada and Japan
  • Traveled extensively in Europe, Far East, and North America
  • Worked as management consultant, computer systems analyst, college instructor and freelance writer.
Akira Kato
Everything on
007 James Bond
from Amazon.com

Beaverland Forum
Featuring thought-provoking
columns and stories
inserted by FC2 system