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.
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.
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.
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.
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.