In this article, I show you how to create simple Java Script animations. The type of animation you will learn to create can be used for advertising purposes or maybe to create a children's animated ebook.
Welcome to Bucaro TecHelp!

Welcome to Bucaro TecHelp!
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact Advertise on Bucaro TecHelp Advertise Here RSS News Feeds News Feeds

HTML5 Solutions: Essential Techniques for HTML5 Developers

Essential Techniques for HTML5 Developers

HTML5 brings the biggest changes to HTML in years. Web designers now have new techniques, from displaying video and audio natively in HTML, to creating realtime graphics on a web page without a plugin.

This book provides a collection of solutions to all of the most common HTML5 problems. Every solution contains sample code that is production-ready and can be applied to any project.

Click Here

Easy Java Script Animation

In this article, I show you how to create simple Java Script animations. The type of animation you will learn to create can be used for advertising purposes or maybe to create a children's animated ebook.

There are two kinds of animation, sprite animation and frame animation. Frame animation is nothing more than a fast slide show. You create a set of slides or frames with a small change in each frame. When the frames are displayed in quick succession, the changes appears as motion.

Sprite animation is when you move one image, referred to as a sprite over a background image. A sprite is a rectangular image, but the parts of the image where you want the background to show through are made transparent. One sprite can move in front of another sprite. The sprite closest to the viewer has the highest z order.

A good animation has sprite images that are themselves small frame animations moving over a background. The example that I present here uses simple non-animated sprites. It is possible to create animated sprites with Java Script, but I leave that for a future article.

One serious limitation of Java Script sprite animation is that you can't make a sprite with a transparent background. You can make a non-rectangular sprite by making parts of the image the same color as the background, thus faking transparency. This means either your sprites will have to be rectangular, or you can't let one sprite move in front of another sprite, or over background graphics. You can observe this problem in the example animation shown below.

View Example

The first step is to create the graphics. For this example I use a simple graphic of a blue circle for the sprite and a solid blue graphic for the background. To make the rectangular sprite appear round, I color the areas outside the circle the same color as the background. You don't have to use a plain colored background. But if the image on your sprite is not rectangular, you need to carefully plan where you move your sprite during the animation sequence.

The most important thing for you to understand in order to create an animation is pixel coordinates. The origin of your computer screen is the upper-left corner. This location has the coordinate x=0,y=0. As you move horizontally across the screen the x coordinate increases. As you move down from the top of the screen the y coordinate increases.

You can determine your screen area by selecting Start | Settings | Control Panel, open the Display utility and click on the Settings tab. If your screen area is 1024 x 768 pixels, the coordinate of the center of your screen is x=612,y=384.

Your web browser window uses a similar coordinate system. The origin is the upper-left corner of the browser window, below the tool bar. This location has a coordinate of x=0,y=0. The browser window uses the same scale as the screen, but since the browser window is re-sizable, it's area and the coordinates of its center can change.

To place your background image on your web page use the image tag as shown below.

<img src="background.gif">

To place your sprite on the screen, define a span as shown below.

<span id="ball1" style="position:absolute; visibility: visible; top:30; left:30; width:32; height:32; z-index:2"><img border=0 width=32 height=32 src="ball.gif"></span>

I have given the span the identifier ball1, and using style notation, defined it's location in the browser window as x=30,y=30. In the example I created a second span, containing the same ball image, but giving it the identifier ball2 and setting the z-index to 1.

Note: You don't have to understand every attribute of the code here to use it. It's a fact that all great programmers started out by copying and pasting code and playing around with it until it does what they want.

RSS Feed RSS Feed



Web Design Sections

Eloquent JavaScript: A Modern Introduction to Programming

Eloquent JavaScript

Eloquent JavaScript Eloquent JavaScript goes beyond the cut-and-paste scripts of the recipe books and teaches you to write code that's elegant and effective. You'll start with the basics of programming, and learn to use variables, control structures, functions, and data structures. Then you'll dive into the real JavaScript artistry: higher-order functions, closures, and object-oriented programming.

Reader Anthony says, "This book is not your typical Javascript book. Others have a utilitarian approach. In stark contrast, Eloquent JavaScript does not merely provide you a checklist of things to learn but rather paints a panorama of the possibilities that programming provides. Javascript is merely the tool used to introduce these to the reader.

Click here for more information.


[Site User Agreement] [Advertise on This site] [Search This Site] [Contact Form]
Copyright©2001-2011 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268