Ryan's District
September 07, 2008, 02:34:39 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length

There are currently users in chat
News: Ryan's District Lottery: Claim your ticket or check
Jackpot details  
 
   Home   Help Search Chat Calendar Chess Shop Login Register  
Digg This!
Pages: [1]   Go Down
  Send this topic  |  Print  
Author Topic: Java - Animated JPGS  (Read 2357 times)
0 Members and 1 Guest are viewing this topic.
ben2ong2
Quality Poster
Paid
Hero Member
*****

Reputation: 17
Offline Offline

Gender: Male
Posts: 2374
9976.80 RD$

View Inventory
Send Money to ben2ong2

View Profile Awards
« on: October 04, 2006, 03:00:31 AM »


We've all heard of animated gifs and most of us would have made some for our web sites. Such gifs can be created using many commercial and free programs.
The animated gifs are a series of images (frames) that are played sequentially giving the semblance of motion/change. The Gif89a gif format supports animation along with transparency.

The jpg image format has no provision for animation, however, with a little JavaScript and a dash of creativity, we can easily make an "animated" jpg.
You should keep in mind that the animated jpg is not one image but a series of images that are displayed in the same place in the browser.

We start by preloading all the jpg images required in the "animation".


The second step is to use a function that changes the source of an image. Finally, we call this function repeatedly by employing the setTimeout() method.



var c = 1;

/* Preloading images */
var image1 = new Image();
image1.src = "a1.jpg";
var image2 = new Image();
image2.src = "a2.jpg";
var image3 = new Image();
image3.src = "a3.jpg";
var image4 = new Image();
image4.src = "a4.jpg";
var image5 = new Image();
image5.src = "a5.jpg";

function disp_img(w)
   {
   if (c == 6)
      {
      c = 1;
      }
   var img_src = "a" + c + ".jpg";
   document.ani.src = img_src;
   c++;
   }
t = setInterval("disp_img(c)", 1000);
The entire script is placed inside the HTML document HEAD section.
We start by initializing a global variable c that serves as a counter and is also a part of the image name. After preloading the images (an1.jpg, an2.jpg, an3.jpg, an4.jpg and an5.jpg), we define a function disp_img() that changes the source of images named ani. The function also checks the value of variable c, assigning it a value of 1 if its value exceeds 5. The variable is also incremented each time the function is called. The function is called after every 1 second (1000 milliseconds) with the setInterval() method.

You can customize the script and create .jpg slide-shows easily.

Note: These "animated" jpgs will not work on older browsers than have no JavaScript support and also on browsers than have JavaScript disabled.

Logged

You are not allowed to view links.
Register or Login
Free Paid Survey & Home Business Resources.

You are not allowed to view links.
Register or Login
Free Article Directory | Quality Content
Ryan's District
   

 Logged
Pages: [1]   Go Up
  Send this topic  |  Print  
 
Jump to:  

Archive - WAP2 - WAP - imode
Sponsors: TOP SEO Directory - Online Job Maker - List of Advertisers - BIG VENUE

Powered by MySQL Powered by PHP Powered by SMF 1.1.5 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.179 seconds with 28 queries.

Google visited last this page Yesterday at 01:26:22 PM