| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
How to reduce an
animation-file size
with Javascript by Akira Kato
August 25, 2003
Move your mouse over her hair band.
The above Javascript animation consists of the following two 16-million-color JPEG images.
With Javascript, you can create the same animation without any reduction of its quality. Besides, the file size of both pictures is only 35KB.
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
</td></tr> 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> </table>
<script language="javascript"> var myTimerID=null
function displayWink() {
function displaySpacer() {
function stopAnim() {
//--->
The green square in the above is defined as
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 ( The Javascript engine waits for
2,000 milliseconds or 2 seconds, then it invokes
another function ( The Javascript engine waits another 2 seconds, and then
invokes the function ( 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 (
For more information, please visit the following links:
Related Links
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|