Home arrow HTML arrow Page 4 - Changing and Moving Pictures with CSS

Changing and Moving Pictures with CSS

There are a number of ways you can incorporate images into your web site. If you're adding them to make your web site more dynamic, you probably want to venture beyond images that just sit there all the time. In this article, you'll learn how to make your pictures do something, with a little help from CSS, JavaScript, and HTML.

Author Info:
By: Chrysanthus Forcha
Rating: 4 stars4 stars4 stars4 stars4 stars / 62
June 09, 2008
  1. · Changing and Moving Pictures with CSS
  2. · Moving Pictures Demonstration
  3. · CSS Properties to Use
  4. · Algorithm

print this article

Changing and Moving Pictures with CSS - Algorithm
(Page 4 of 4 )

Here I explain the algorithm for both examples.

  • Since an image with absolute position would cover elements in normal flow, do not put any element in normal flow under the image stack. In these examples, the image stack is put in a table cell that has no content. The dimensions of the table cell are the same as the dimensions of each of the image. The images all have the same dimensions.

  • At any instant we see only the image in front. So give the image that is to appear in front a z-index value of 2, and give the rest that come behind a z-index value of 1. With a z-index value of 1, they will still be placed in order, but this time their order will depend in the order they were placed in the normal flow.

  • Use a timing function inside an infinite loop to changing the z-indices (2 and 1) of the images in the stack.

Changing Images

In this section I talk about the first example. The images all concern themselves with the topic of education. So while the user is reading other things on the web page, the changing images are calling his attention to education or a particular aspect of education. The time interval between each new picture coming up is 1000ms (1s).

The variables A, B, C, D and Temp are used to change the z-index values of the images each time the function "beChanging()" is called.

You can now read through the code of the first example and fully understand it.

Moving Images

In this section I talk about the second example. Here we are dealing with moving images (video). The images are indicated below in the order (from left to right, top to bottom) in which they are displayed.

Fig1. Similar images in order

The aim here is to display a ball that moves through an arc repeatedly. So the order of the images must always be respected. From one image to the next, there is only a small difference in the picture. The images above have been listed in the order in which they appear on the screen. After the last image appears, the cycle repeats. The code is similar to the one above, but here you must respect the order in the stack to have a continuous movement of the ball. Also, here the time interval is smaller: 100ms.

Application of moving CSS/JavaScript images

When you do something like what we have done for the second example, you actually form a video clip. If you want the movement to be very natural you need to display at least 25 similarly varying images in one second. This means that the time interval has to be at most 40ms. The problem here is that 25 images will take a long time to download. So you can limit this technique to highlights of scenes where you will use fewer images.


You can develop your own small clips using HTML, CSS and JavaScript. You put the images in layers to form a stack. Use a JavaScript function to rotate the image positions in the stack.

DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus

- Does HTML5 Need a Main Element?
- Revisiting the HTML5 vs. Native Debate
- HTML5: Not for Phone Apps?
- HTML5 or Native?
- Job Hunting? Freelancer.com Lists This Quart...
- HTML5 in the News
- Report: HTML5 Mobile Performance Lags
- The Top HTML5 Audio Players
- Top HTML5 Video Tutorials
- HTML5: Reasons to Learn and Use It
- More of the Top Tutorials for HTML5 Forms
- MobileAppWizard Releases HTML5 App Builder
- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials