Blue Theme Orange Theme Green Theme Red Theme
 
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Team Foundation Server Hosting
Search :       Advanced Search »
Home » JavaScript » Image Animation in JavaScript

Image Animation in JavaScript

This article provides the simple way to understand the Image Animation using JavaScript.

Author Rank :
Page Views : 30591
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

Introduction:

 

This article allows you to display what appears to be a single image animation using three different images. The images in the animation will need to be all the same size. The animation repeats indefinitely.

 

The first image will be placed on the page and set the height and width. Image name should specify in the <img> tag like this:

 

<img src="Blue hills.jpg" name="demo" border= "2px" width="100" height="100" alt="demo">

 

Example: See the following example to understand the multiple image animation.

 

JavaScript is given as follows within <head> and <body>tag.

 

<html>

  <head>

  <title>ImageAniation</title>

    <script language="JavaScript">

    // Preloaded images

    if (document.images)

    {

      demo1 = new Image();

      demo1.src = "Sunset.jpg"

 

      demo2 = new Image();

      demo2.src = "Water-lilies1.jpg";

 

      demo3 = new Image();

      demo3.src = "Winter.jpg";

    }

    // Reusable timer

    function timeimgs(numb)

    {

      thetimer = setTimeout("imgturn('" +numb+ "')", 1000);

    }

    // Reusable image turner

    function imgturn(numb)

    {

      if (document.images)

      {

        // This will loop the image

        if (numb == "3")

        {

          document["demo"].src = eval("demo3.src");

          timeimgs('1');

        }

        else

        {

          document["demo"].src = eval("demo" + numb + ".src");

          timeimgs(numb = ++numb);

        }

      }

    }

    </script>

  </head>

  <body bgcolor="olive" onload="timeimgs('2');">

    <font color= purple><h2>Image Animation</h2></font>

    <img src="Blue hills.jpg" name="demo" border= "2px" width="100" height="100" alt="demo">

  </body>

</html>

 

Output:

 

To view the output copy this script and paste on your HTML page within <html> tag. You have to change the image name in this example when you paste on your HTML page.

 

You will see the output something like this:

 

 

 

Figure 1: This image will display at starting.

 

After one second following image will display at same position (according to this example).

 

 

 

Figure 2: Second image is displaying.

 

All images will display one by one with same time interval.

 

 

 

Figure 3:

 

 

Figure 4:

 

You will understand this article when you see the output in a proper way. So copy and paste this script on html page and try to understand.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Purushottam Rathore

I am working as a Software Developer and has 4 years of experience on Microsoft Technology and having a Master Degree in Computer Application. I really like to work in the .NET platform. and working with ASP.NET 2.0/3.5, Web Services, WPF, WCF, Silverlight, AJAX, JavaScript, JQuery, Ado.net, MsAccess, SQL Server 2005/2008.

Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Nevron Gauge for SharePoint
Become a Sponsor
 Comments
try this code by Bechir On February 21, 2008
I think the we can do all this in one function thanks to the recursivity concept function RullOver() { if(document.images) { window.setTimeout("document['myImage'].src = '../../../Images/Image1.jpg';",2000); window.setTimeout("document['myImage'].src = '../../../Images/Image2.jpg';",3000); window.setTimeout("document['myImage'].src = '../../../Images/Image3.jpg';",4000); window.setTimeout("document['myImage'].src = '../../../Images/Image4.jpg';",5000); setTimeout("RullOver();",5000); } }
Reply | Email | Modify 
quick question by Melat On December 5, 2010
I just want to make the animation stop on the last image, I don't want it to repeat itself, can u tell me how i can do that. thanks 
Reply | Email | Modify 
Problem in Google Chrome by Cariinfo On March 23, 2011
I'd tried this script in my web editor. It worked fine with IE, but not with Google Chrome (that the function of Javascript seemed not running at all). Does anybody know how to fix it, or could you please? Thank you.
Reply | Email | Modify 
6 Months Free & No Setup Fees ASP.NET Hosting!
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.