Introduction
In this article, we show image animation using a web application in TypeScript.
The following example shows an animation using a web application in TypeScript. In this example, we create a Run function and this function calls an unload event of the window so when the page is loaded the Run function will be called. In the Run function, we call another function using the setTimeout function.
Step 1
Open Visual Studio 2012 and click "File" -> "New" -> "Project...". A window is opened. In this window, click "HTML Application for TypeScript" under "Visual C#".
Give the name of your application as "Image_Animation" and then click ok.
Step 2
After this session, the project has been created; a new window is opened on the right side. This window is called the Solution Explorer. The Solution Explorer contains the ts, js and CSS files and the aspx page.
Coding
app.ts
- class Image_Animation {
- Run() {
- var img = ( < HTMLImageElement > document.getElementById("image1"));
- img.src = "Image1.jpg";
- img.style.visibility = "visible";
- setTimeout(() => {
- this.Run1();
- }, 1000);
- }
- Run1() {
- var img = ( < HTMLImageElement > document.getElementById("image2"));
- img.src = "Image2.jpg";
- img.style.visibility = "visible";
- setTimeout(() => {
- this.Run2();
- }, 1000);
- }
- Run2() {
- var img = ( < HTMLImageElement > document.getElementById("image3"));
- img.src = "Image3.jpg";
- img.style.visibility = "visible";
- setTimeout(() => {
- this.Run3();
- }, 1000);
- }
- Run3() {
- var img = ( < HTMLImageElement > document.getElementById("image4"));
- img.src = "Image4.jpg";
- img.style.visibility = "visible";
- setTimeout(() => {
- this.Run4();
- }, 1000);
- }
- Run4() {
- var img = ( < HTMLImageElement > document.getElementById("image5"));
- img.src = "Image5.jpg";
- img.style.visibility = "visible";
- setTimeout(() => {
- this.Run5();
- }, 1000);
- }
- Run5() {
- var img = ( < HTMLImageElement > document.getElementById("image6"));
- img.src = "Image6.jpg";
- img.style.visibility = "visible";
- setTimeout(() => {
- this.Run6();
- }, 1000);
- }
- Run6() {
- var img = ( < HTMLImageElement > document.getElementById("image7"));
- img.src = "Image7.jpg";
- img.style.visibility = "visible";
- setTimeout(() => {
- this.Stop();
- }, 2000);
- }
- Stop() {
- var img1 = ( < HTMLImageElement > document.getElementById("image1"));
- var img2 = ( < HTMLImageElement > document.getElementById("image2"));
- var img3 = ( < HTMLImageElement > document.getElementById("image3"));
- var img4 = ( < HTMLImageElement > document.getElementById("image4"));
- var img5 = ( < HTMLImageElement > document.getElementById("image5"));
- var img6 = ( < HTMLImageElement > document.getElementById("image6"));
- var img7 = ( < HTMLImageElement > document.getElementById("image7"));
- img1.style.visibility = "hidden";
- img2.style.visibility = "hidden";
- img3.style.visibility = "hidden";
- img4.style.visibility = "hidden";
- img5.style.visibility = "hidden";
- img6.style.visibility = "hidden";
- img7.style.visibility = "hidden";
- setTimeout(() => {
- this.Run();
- }, 1000);
- }
- }
- window.onload = () => {
- var obj = new Image_Animation();
- obj.Run();
- };
Image_Animation_Demo.aspx