|
|

|
|
Filters and Transitions
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
IntroductionWhen Microsoft released Internet Explorer 4 they included a selection of filters and transitions that allow multimedia-style effects in plain HTML web pages. They can be applied to any HTML control, such as DIV tags, form fields or images. Internet Explorer 5 for Windows built on the existing functionality with more advanced transitions and a different method of applying filters. To see the examples in this tutorial you have to be using Internet Explorer 4+. Static FiltersInternet Explorer 4+ The static filters can be applied to any HTML control through the style tag:
or at runtime through javascript:
both produce this red drop shadow(note: for some reason you must specify the width and height attributes for the filter to work)
The best way to use these filter properties is to use WebFX's Filter Tool, you can also check the Microsoft Documentation, except this has been updated to work with the IE5.5+ method of applying filters. Internet Explorer 5.5+ With IE5 Microsoft have changed the way filters are applied, they still use the filter property of the style tag, but uses different syntax. In HTML:
and from code:
If you look at the Microsoft Documentation you will notice several other filters such as Light, Compositor and Matrix. These work a little differently than the others and probably best if you look at the specific documentation when you are interested. Transitions
These (as far as I am aware) only work in Internet Explorer 5.5+ for Windows. It is therefore necessary to start off with a browser and OS check. See the DHTML library tutorial for more info about that.
Now we need to know how to use them. To find the properties of each transition look at the Microsoft Documentation (if I find the time I may make a utility similar to the WebFX one linked above). We'll start off with the fade transition that takes a single property "duration": All that is gold does not glitter,Not all those who wander are lost; The old that is strong does not wither, Deep roots are not reached by the frost. Now here is the function that does the above:
Now this may seem a bit complicated so I'll brake it down into 4 important
stages: To see how to use transitions with the CoolMenus script check example 14 where you can try all the different filters. Appendix A - The Matrix TransformationIn the field of Computer Graphics matrices are used to speed up and simplify certain calculations. For example, your 3D-graphcs card has special hardware that uses a 4x4 matrix to rotate, translate or stretch points in 3-dimensions, thus speeding up calculations that are normally done by the main processor.
Now, if this is applied to each pixel in an image, we can get some very interesting results. Example: rotation In order to rotate a point around the origin (0,0) you can find the new values of x and y using the following equations (if you don't believe here's a proof for one of the equations): newX = x*cos(Ø) - y*sin(Ø) newY = x*sin(Ø) + y*cos(Ø)Now it can be seen that we can use the following matrix to rotate a point:
Using the Matrix Filter
var el = document.getElementById(name);
el.style.filter = "progid:DXImageTransform.Microsoft.Matrix()";
el.filters.item("DXImageTransform.Microsoft.Matrix").[property] = [value];
ExampleThis example uses the rotation matrix described above to cause the box to spin. It should be noted that the code has to take into account that the dimensions of the container change size in order to keep the box centred. Here's the code for the function that will rotate an object by an arbitrary angle:
function rotate(name, angle){ //convert angle into radians
var rad = degToRad(angle);
//calculate cos and sin of the angle
costheta = Math.cos(rad);
sintheta = Math.sin(rad);
//create object reference
var el = document.getElementById(name);
if(el) {
//apply the filter
el.style.filter = "progid:DXImageTransform.Microsoft.Matrix()";
//set up the properties
el.filters.item("DXImageTransform.Microsoft.Matrix").SizingMethod = "auto expand";
el.filters.item("DXImageTransform.Microsoft.Matrix").FilterType = "bilinear";
//apply the rotation matrix transformation
el.filters.item("DXImageTransform.Microsoft.Matrix").M11 = costheta;
el.filters.item("DXImageTransform.Microsoft.Matrix").M12 = -sintheta;
el.filters.item("DXImageTransform.Microsoft.Matrix").M21 = sintheta;
el.filters.item("DXImageTransform.Microsoft.Matrix").M22 = costheta;
}
}
This code calls the rotation function and recentres the DIV. In order to do this we need to use the offset values since the style's properties aren't updated:
var angle = 0;
function doRotate() {
//check to make sure angle is between 0 and 360 degrees
if(angle>360) angle-=360;
//increment angle
angle+=15;
//do rotation
rotate("aDiv",angle);
//recentre div using offset values
var el = document.getElementById("aDiv");
el.style.top = 25 - (el.offsetHeight/2);
el.style.left = 25 - (el.offsetWidth/2);
setTimeout("doRotate();",10);
}
And there you have it! Have fun playing, and if you want to get further information on the Matrix
Filter visit the MSDN site.
Copyright ©2000-2002 DHTMLCentral.com, Bratta Communications. All rights reserved. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||