How to Create a Basic HTML+TIME Transition | DHTML文档教程 |
This tutorial shows you how to use HTML+TIME (Timed Interactive Multimedia Extensions) transitions to allow an element to transition into view and then transition the element out of view. This is an example of using HTML+TIME transitions at a very basic level. Click the following Show Me button to see the sample you can create.
To start, have a quick look at the code of the entire sample. Later on, this code is explained in greater detail, but for now, it might be useful to have a preview of what is needed to make the sample.
<HTML XMLNS:t = "urn:schemas-microsoft-com:time"> <HEAD> <STYLE> .time {behavior: url(#default#time2);} #oDiv { border:2px solid black; font:18pt arial; padding:20; color:#000000; background-color:#FFCC00; width:270px; height:270px; } </STYLE> <?import namespace = t urn = "urn:schemas-microsoft-com:time" implementation = "#default#time2" /> </HEAD> <BODY> <DIV ID="oDiv" BEGIN="1" CLASS="time" DUR="8"> <t:TRANSITIONFILTER BEGIN="oDiv.begin" DUR="3" TYPE="fade"/> <t:TRANSITIONFILTER BEGIN="oDiv.end - 3" DUR="3" MODE="out" TYPE="pushWipe"/> This DIV Transitions In, Stays For Two Seconds, And<br> Then Transitions Out. </DIV> </BODY> </HTML>
as you can see, the code is relatively short. besides the div element, there are only two t:TRANSITIONFILTER elements inside of the body of the document. It is these t:TRANSITIONFILTER elements and the attributes inside of them that control the timing and characteristics of the transition that is applied to the DIV element. This tutorial walks through each of the following steps to create the sample.
to use html+time elements and use the time2 behavior, the following code is needed.
<HTML XMLNS:t = "urn:schemas-microsoft-com:time"> <HEAD> <STYLE> .time {behavior: url(#default#time2);} </STYLE> <?import namespace = t urn = "urn:schemas-microsoft-com:time" implementation = "#default#time2" /> </HEAD> <BODY> </BODY> </HTML>
For more information about creating an XML namespace and referencing the time2 behavior, see authoring html+time.
next, we add the formatting code inside of the style tags. the div element in this sample derives its formatting from here. by separating formatting code from rendered elements, the functional code is simplified.
<STYLE> .time {behavior: url(#default#time2);} #oDiv { border:2px solid black; font:18pt arial; padding:20; color:#000000; background-color:#FFCC00; width:270px; height:270px; } </STYLE>
You must then create an element that you want to transition. For this sample, we use a DIV.
<DIV id="oDiv" STYLE="width:270" CLASS="time" BEGIN="3" DUR="8"> This DIV Transitions In, Stays For Two Seconds, And Then Transitions Out. </DIV>
Let's take a closer look at this DIV. There are a number of features worth mentioning.
First, the element must have layout in order to have an HTML+TIME transition applied to it. The DIV in this tutorial gains layout by having the width and height specified inside the STYLE tag that you included.<STYLE> #oDiv { . . width:270px; height:270px; . . } </STYLE>
For more information about what is needed to gain layout, see What Can Be Transitioned?.
The class attribute is set to time, which applies the time2 behavior to the DIV. This, too, is needed allows the DIV to have the transition applied to it.
The begin attribute had a value of 3. This means that the element appears three seconds after the page loads.
The dur attribute is set to a value of 8 (eight seconds). Because we want to transition the DIV out of view, it must have a finite duration that it is visible. The period of time that the element is visible is known as the active period of the element.
Let's take a look at the sample so far.
<HTML XMLNS:t = "urn:schemas-microsoft-com:time"> <HEAD> <STYLE> .time {behavior: url(#default#time2);} #oDiv { border:2px solid black; font:18pt arial; padding:20; color:#000000; background-color:#FFCC00; width:270px; height:270px; } </STYLE> <?import namespace = t urn = "urn:schemas-microsoft-com:time" implementation = "#default#time2" /> </HEAD> <BODY> <DIV ID="oDiv" BEGIN="1" CLASS="time" DUR="8"> This DIV Transitions In, Stays For Two Seconds, And<br> Then Transitions Out. </DIV> </BODY> </HTML>
as you can see, the div appears and disappears, but no transitions take place yet. next, we see how to transition the div into view.
the first t:transitionfilter in the example controls the div transitioning into view.
<DIV id="oDiv" STYLE="width:270" CLASS="time" BEGIN="3" DUR="8" > <t:TRANSITIONFILTER BEGIN="oDiv.begin" DUR="3" TYPE="fade"/> This DIV Transitions In, Stays For Two Seconds, And Then Transitions Out. </DIV>
The BEGIN attribute is set to oDiv.begin. This specifies that the transition element is to begin at the same time as the DIV on the time line. It is important to realize that t:TRANSITIONFILTER elements have a beginning, duration of activity, and end that correspond to the state of the transition. Because the DIV appears to transition from invisible to visible, the t:TRANSITIONFILTER begins at the same time as the DIV. Of course, the t:TRANSITIONFILTER could be started at any time during the active period of the DIV but the results would probably be undesirable.
The DUR attribute specifies how long the t:TRANSITIONFILTER is active. This specifies how long the transition takes to complete. The transition finishes after three seconds; therefore, the DIV becomes fully visible after three seconds. At this point, three seconds of the DIV's total active duration of eight seconds has already expired.
The TYPE attribute specifies the kind of transition that takes place. In this case, the transition fades into view.
Here is the sample so far.
<HTML XMLNS:t = "urn:schemas-microsoft-com:time"> <HEAD> <STYLE> .time {behavior: url(#default#time2);} #oDiv { border:2px solid black; font:18pt arial; padding:20; color:#000000; background-color:#FFCC00; width:270px; height:270px; } </STYLE> <?import namespace = t urn = "urn:schemas-microsoft-com:time" implementation = "#default#time2" /> </HEAD> <BODY> <DIV ID="oDiv" BEGIN="1" CLASS="time" DUR="8"> <t:TRANSITIONFILTER BEGIN="oDiv.begin" DUR="3" TYPE="fade"/> This DIV Transitions In, Stays For Two Seconds, And<br> Then Transitions Out. </DIV> </BODY> </HTML>
the second t:transitionfilter in the example controls the div transitioning out of view.
<DIV id="oDiv" STYLE="width:270" CLASS="time" BEGIN="3" DUR="8" > <t:TRANSITIONFILTER BEGIN="oDiv.begin" DUR="3" TYPE="fade"/> <t:TRANSITIONFILTER BEGIN="oDiv.end - 3" DUR="3" MODE="out" TYPE="pushWipe"/> This DIV Transitions In, Stays For Two Seconds, And Then Transitions Out. </DIV>
The mode attribute is set to out. this attribute specifies whether the div becomes more or less visible as the transition proceeds. the value of out specifies that the div becomes less visible. a value of in would specify that it becomes more visible. because in is the default value, the mode attribute did not need to be included in the first t:transitionfilter element.
the begin attribute is set to odiv.begin - 3. this t:transitionfilter element begins three seconds before the div ends on the time line. the dur value of this t:transitionfilter is three seconds, so the transition ends at the exact same time as the div ends. like the first transition, it is important to get this timing right. for instance, if the t:transitionfilter begins too early, the div would transition out for a moment, appear again, and then disappear when the active period of the div elapsed. if the t:transitionfilter starts too late, the div would transition out part of the way and then suddenly disappear because the t:transitionfilter cannot extend the duration of the div. as expected, if the active periods of the t:transitionfilter and the div do not overlap at all, no transition occurs on the div.
here is the completed sample.
<HTML XMLNS:t = "urn:schemas-microsoft-com:time"> <HEAD> <STYLE> .time {behavior: url(#default#time2);} #oDiv { border:2px solid black; font:18pt arial; padding:20; color:#000000; background-color:#FFCC00; width:270px; height:270px; } </STYLE> <?import namespace = t urn = "urn:schemas-microsoft-com:time" implementation = "#default#time2" /> </HEAD> <BODY> <DIV ID="oDiv" BEGIN="1" CLASS="time" DUR="8"> <t:TRANSITIONFILTER BEGIN="oDiv.begin" DUR="3" TYPE="fade"/> <t:TRANSITIONFILTER BEGIN="oDiv.begin+5" DUR="3" MODE="out" TYPE="pushWipe"/> This DIV Transitions In, Stays For Two Seconds, And<br> Then Transitions Out. </DIV> </BODY> </HTML>