Animating Parts of HTML Elements - taccGL™ Tutorial
Rectangular Parts - Clip
Sample HTML Element
containing some text.
taccgl™ has various methods to restrict a transition to operate only on a part of an
HTML element. This is useful to select a part of an image or a texture
for an animation and it is used often to split an element into parts that
move independently.
The first example below selects the upper left part of the sample element
starting at an x- and y-offset of 11px with width 300px and height 200px.
It uses the clip method, which receives the coordinates of the top left
corner of the selected portion, the width and the height as parameters.
The second example uses the second form of clip which gets
the upper left and the lower right point as parameters.
The third example applies this to animate the left and right half
of the element independently using a first transition for the left
half and a second rotating transition for the right half, creating a kind of fold effect.
taccgl.actor("htmlel").clip ({ox:11, oy:11}, 300, 200) . dur(3). start(); | RUN |
taccgl.actor("htmlel").clip ({}, {rx:0.5,ry:1}) . dur(3). start(); | RUN |
taccgl.actor("htmlel").clip ({}, {rx:0.5,ry:1}) . dur(3). start(); taccgl.actor("htmlel").clip ({rx:0.5}, {rx:1,ry:1}) . rotate ({rx:0},0,1,0) . rotatePart(0,-Math.PI) . dur(3). start(); | RUN |
Animating Clip - ClipFrom and ClipTo
Sample HTML Element
containing some text.
It is possible to give different restrictions for the begin
(clipFrom) and the end (clipTo) of a
transition to create a kind of clipping animation. The first
example uses clipTo to restrict to an almost empty
1x1 portion. Sinces clipFrom is not given the default
is "no restriction". In total this creates a clipping animation
that makes the element vanish. Vice versa the second example
makes an element appear.
taccgl.actor("htmlel5").clipTo ({},1,1) . dur(3). start(); | RUN |
taccgl.actor("htmlel5").clipFrom ({rx:1},1,1) . dur(3). start(); | RUN |
taccgl.actor("htmlel5").clipFrom ({},0,0) . dur(3). start(); | RUN |
taccgl.actor("htmlel5").clipFrom ({}, {rx:0.5,ry:1}).clipTo ({rx:0.5}, {rx:1,ry:1}) . dur(3). start(); | RUN |
taccgl.actor("htmlel5").clipFrom ({rx:-0.5}, {rx:0,ry:1}).clipTo ({rx:1}, {rx:1.5,ry:1}) . dur(3). start(); | RUN |
Triangluar Parts
HTML Element With some text.
By using taccgl.triangle as second parameter of actor the top left triangle
of an HTML element can be selected (1st example below). clip can
be used as explained above (2nd example below) in order to move the top left
corner of the triangle and to change height and width.
Note that the second point given to restrict does not neccesarily need to be right or below
the first point (or height and width given to clip can be negative).
This way it is possible to select the upper right, bottom left, and bottom right triangle
of an HTML element as shown in the 3rd-5th examples below.
taccgl.actor("htmlel3",taccgl.triangle). to({ox:-500,oy:500}). dur(3). start(); | RUN |
taccgl.actor("htmlel3",taccgl.triangle).clip ({ox:11, oy:11}, 300, 200) . dur(3). start(); | RUN |
taccgl.actor("htmlel3",taccgl.triangle).clip ({rx:1}, {ry:1}) . dur(3). start(); | RUN |
taccgl.actor("htmlel3",taccgl.triangle).clip ({ry:1}, {rx:1}) . dur(3). start(); | RUN |
taccgl.actor("htmlel3",taccgl.triangle).clip ({rx:1,ry:1}, {}) . dur(3). start(); | RUN |
taccgl.actor("htmlel3",taccgl.triangle). from({rx:-2,ry:2}). dur(3). start(); taccgl.actor("htmlel3",taccgl.triangle).clip ({rx:1,ry:1}, {}).from({rx:-2,ry:2}). dur(3). start(); | RUN |
taccgl.actor("htmlel3",taccgl.triangle). from({rx:-2,ry:2}). dur(3). start(); taccgl.actor("htmlel3",taccgl.triangle).from({rx:1,ry:-1}).clip ({hx:1,hy:1}, {hx:0,hy:0}). dur(3). start(); | RUN |
Selecting an arbitrary Triangle Portion - clipT
HTML Element With some text.
Using clipT it is possible to specify all three corners of the selected triangle.
It gets three parameters each giving the coordinates of one of the triangles corners.
taccgl.actor("htmlel30",taccgl.triangle).clipT({ox:11,oy:11},{rx:1,oy:11,ox:-11},{oy:250,ox:100}). dur(3). start(); | RUN |
taccgl.actor("htmlel30",taccgl.triangle).clipT({},{rx:1},{rx:0.5,ry:0.5}). dur(3). start(); | RUN |
taccgl.actor("htmlel30",taccgl.triangle).clipT({},{rx:0.5},{rx:0.5,ry:0.5}). dur(3). start(); | RUN |
taccgl.actor("htmlel30",taccgl.triangle).clipT({},{rx:1},{rx:0.5,ry:0.5}). from({oy:-100}).dur(3). start(); taccgl.actor("htmlel30",taccgl.triangle).clipT({ry:1},{ry:1,rx:1},{rx:0.5,ry:0.5}). from({oy:100}).dur(3). start(); taccgl.actor("htmlel30",taccgl.triangle).clipT({},{ry:1},{rx:0.5,ry:0.5}). from({ox:-100}).dur(3). start(); taccgl.actor("htmlel30",taccgl.triangle).clipT({rx:1},{rx:1,ry:1},{rx:0.5,ry:0.5}). from({ox:100}).dur(3). start(); | RUN |
Just as with clipFrom and clipTo there
are clipTFrom and clipTTo for
animating.
taccgl.actor("htmlel30",taccgl.triangle).clipTFrom({ox:11,oy:11},{rx:1,oy:11,ox:-11},{oy:250,ox:100}). dur(3). start(); | RUN |
taccgl.actor("htmlel30",taccgl.triangle).clipTFrom({},{rx:1},{rx:0.5,ry:0.5}). dur(3). start(); | RUN |
taccgl.actor("htmlel30",taccgl.triangle).clipTTo({},{rx:0.5},{rx:0.5,ry:0.5}). dur(3). start(); | RUN |
Selecting an arbitrary Triangle Portion - clipR
HTML Element With some text.
clipR is another way to select an arbitrary triangle. It receives 3 pairs of parameters (i.e. 6 numbers). The first pair gives
coordinates of the top left corner. The second and third pair width and height in vector form.
All numbers are relative to the element, whereby 0 means left or top and 1 right or bottom.
The following two examples demonstrate this.
taccgl.actor("htmlel40",taccgl.triangle).clipR(0,0,1,0,0,1). dur(3). start(); | RUN |
taccgl.actor("htmlel40",taccgl.triangle).clipR(1,1,-1,0,0,-1). dur(3). start(); | RUN |
taccgl.actor("htmlel40",taccgl.triangle).clipR(1,0,-1,0,0,1). dur(3). start(); | RUN |
taccgl.actor("htmlel40",taccgl.triangle).clipR(0,1,1,0,0,-1). dur(3). start(); | RUN |
taccgl.actor("htmlel40",taccgl.triangle).clipR(0,0,1,0,0.5,0.5). dur(3). start(); | RUN |
taccgl.actor("htmlel40",taccgl.triangle).clipR(1,0,0,1,-0.5,0.5). dur(3). start(); | RUN |
taccgl.actor("htmlel40",taccgl.triangle).clipRFrom(0,0,1,0,0,1). dur(3). start(); | RUN |
taccgl.actor("htmlel40",taccgl.triangle).clipRFrom(1,1,-1,0,0,-1). dur(3). start(); | RUN |
taccgl.actor("htmlel40",taccgl.triangle).clipRFrom(1,0,-1,0,0,1). dur(3). start(); | RUN |
taccgl.actor("htmlel40",taccgl.triangle).clipRFrom(0,1,1,0,0,-1). dur(3). start(); | RUN |
taccgl.actor("htmlel40",taccgl.triangle).clipRFrom(0,0,1,0,0.5,0.5). dur(3). start(); | RUN |
taccgl.actor("htmlel40",taccgl.triangle).clipRFrom(1,0,0,1,-0.5,0.5). dur(3). start(); | RUN |
taccgl.actor("htmlel40",taccgl.triangle).clipRTo(0,0,1,0,0,1). dur(3). start(); | RUN |
taccgl.actor("htmlel40",taccgl.triangle).clipRTo(1,1,-1,0,0,-1). dur(3). start(); | RUN |
taccgl.actor("htmlel40",taccgl.triangle).clipRTo(1,0,-1,0,0,1). dur(3). start(); | RUN |
taccgl.actor("htmlel40",taccgl.triangle).clipRTo(0,1,1,0,0,-1). dur(3). start(); | RUN |
taccgl.actor("htmlel40",taccgl.triangle).clipRTo(0,0,1,0,0.5,0.5). dur(3). start(); | RUN |
taccgl.actor("htmlel40",taccgl.triangle).clipRTo(1,0,0,1,-0.5,0.5). dur(3). start(); | RUN |
Parallelogram Shaped Parts using clipR
Sample HTML Element
containing some text.
When using methods clipR or clipT on
full elements, instead of triangles, you can select a
parallelogram shaped part of an element. As for
triangles clipR receives 3 pairs of parameters
(i.e. 6 numbers). The first pair gives coordinates of the top
left corner. The second and third pair width and height in
vector form. All numbers are relative to the element, whereby
0 means left or top and 1 right or bottom. The following two
examples demonstrate this.
As a special case you can also specify a rectangular part with clipR, which
is sometimes shorter than clip if all numbers are relative values, see the third example below.
taccgl.actor("htmlel15") . clipR (0,0, 0.5,0, 0.5,1) . dur(3). start(); | RUN |
taccgl.actor("htmlel15") . clipR (0.5,0, 0.5,0, -0.5,1) . dur(3). start(); | RUN |
taccgl.actor("htmlel15") . clipR (0,0, 0.5,0, 0,1) . dur(3). start(); | RUN |
Just as with clipFrom and clipTo there are clipRFrom and
clipRTo for animating.
taccgl.actor("htmlel15") . clipRFrom (0,0,0.5,0,0,1) . dur(3). start(); | RUN |
taccgl.actor("htmlel15") . clipRFrom (0,0,0.5,0,0,0.5) . dur(3). start(); | RUN |
taccgl.actor("htmlel15") . clipRFrom (0.5,0.5,1,0,0,1) . dur(3). start(); | RUN |
taccgl.actor("htmlel15") . clipRFrom (0.25,0.25,0.5,0,0,0.5) . dur(3). start(); | RUN |
taccgl.actor("htmlel15") . clipRFrom (0,0,0.5,0,0,0.5) . clipRTo (0.5,0.5,0.5,0,0,0.5) . dur(3). start(); | RUN |
Finally some examples with clipT:
var t=taccgl.actor("htmlel15"); t.clipT({},{rx:0.5},{rx:0.5,ry:0.5}). dur(3). start(); | RUN |
var t=taccgl.actor("htmlel15"); t.clipT({ry:0.2},{rx:0.2},{rx:0.8,ry:1}). from({hx:-2,hy:-2}). dur(3). start(); taccgl.actor("htmlel15",taccgl.triangle).clipT({ry:0.2},{rx:0.8,ry:1},{rx:0,ry:1}). from({hx:2,hy:2}) .dur(3). start(); taccgl.actor("htmlel15",taccgl.triangle).clipT({rx:0.2},{rx:1,ry:0},{rx:1,ry:0.8}). from({hx:2,hy:2}) .dur(3). start(); | RUN |
Combined Examples
Text appearing Diagonally
Sample HTML Element
containing some text.
The following example makes text appear in a diagonal way. The text is written into the bottom right triangle
of an HTML element. Afterwards using a restrict animation the triangle is made to appear (see first version below).
Then the background color is removed (second version below) and a motion of the HTML is added (third version).
Note that the text needs to fit into the bottom right triangle of the HTML element, which is achieved
by enlarging the HTML element. The element, however, can be hidden and the text can be made to appear
whereever desired using from/to (final version below).
taccgl.actor("htmlel45",taccgl.triangle) .lightBgAmbDiff("lightblue",1,1) .clipTTo({hx:1,hy:1},{hx:1},{hy:1}) .clipTFrom({hx:1,hy:1},{hx:1,hy:1,ox:-1},{hx:1,hy:1,oy:-1}). dur(3). start(); | RUN |
taccgl.actor("htmlel45",taccgl.triangle) .lightBgAmbDiff("white",1,1) .clipTTo({hx:1,hy:1},{hx:1},{hy:1}) .clipTFrom({hx:1,hy:1},{hx:1,hy:1,ox:-1},{hx:1,hy:1,oy:-1}). dur(3). start(); | RUN |
taccgl.actor("htmlel45",taccgl.triangle) .from({hx:-.5,hy:-.5}).clipTTo({hx:1,hy:1},{hx:1},{hy:1}).clipTFrom({hx:1,hy:1},{hx:1,hy:1,ox:-1},{hx:1,hy:1,oy:-1}). vEnd(0,0,0). dur(1). start(); | RUN |
taccgl.actor("htmlel45",taccgl.triangle) .from({hx:-1,hy:-1}).to({hx:-.5,hy:-.5}) .clipTTo({hx:1,hy:1},{hx:1},{hy:1}) .clipTFrom({hx:1,hy:1},{hx:1,hy:1,ox:-1},{hx:1,hy:1,oy:-1}) .vEnd(0,0,0). dur(1). start(); | RUN |
Text appearing behind Triangle
Sample Text
The following example makes some text appear diagonally from nowwhere. In fact the text appears behind
a white triangle. For illustration the first version of the example below shows the triangle in green
and the second one in white. The element with id "htmlel60" contains the text and moves.
The element with id "htmlel61" is illustrated as a blue box and is turned into a triangle while the
animation is running.
taccgl.actor("htmlel61") .from({el:"htmlel60",ex:.5,ey:.5}) .to({el:"htmlel60",ex:0,ey:0}). dur(3).start(); var t=taccgl.a("htmlel60",taccgl.triangle) .lightBgAmbDiff("green",1,1) .alpha(0).hide() .visFinal(); t .clipT({ry:1,rx:1,ox:-t.h},{rx:1},{rx:1,ry:1}).dur(3). showAfter(). start(); | RUN |
taccgl.actor("htmlel61") .from({el:"htmlel60",ex:.5,ey:.5}) .to({el:"htmlel60",ex:0,ey:0}) .dur(3).start(); var t=taccgl.a("htmlel60",taccgl.triangle) .lightBgAmbDiff("white",1,1) .alpha(0).hide() .visFinal(); t.clipT({ry:1,rx:1,ox:-t.h},{rx:1},{rx:1,ry:1}).dur(3). showAfter(). start(); | RUN |
WebGL™ is a trademark of the Khronos Group Inc.
|