Kineticjs Tutorials (7)Author: ysm 7. Graphics Transformations 7.1. Linear change
KineticProvides a graphical object for theTransitionto (config)The method realizes the linear transformation of the graph, that is, from the original state linear transformation to the new state, where the state refers to the parameters on the scale. Method ofConfigParameters are some parameters about the graph scale, such asX,Y,Rotation widthheight strokewidth, alpha centeroffset ET. In addition to these scale parameters, a duration parameter , the unit is the second, which specifies how long the linear transformation is done.
For example, the following code allows the graph to move from its original position to the horizontal axis within two seconds and gradually become transparent:
<script>
Shape.transitionto ({
x:100,
alpha:0,
Duration:2
});
</script>
7.2. Speed in the transformation
Kinetic'sTransitionto (config)Method in theConfigParameters include aEasingproperty, refers to whether the transformation is at a more uniform speed to the transformation destination point or in the transformation process at different speeds at different velocities of the transformation.EasingThe values you can set includeEase-in、Ease-out、Ease-in-out、Back-ease-in、Back-ease-out、Back-ease-in-out、Elastic-ease-in, elastic-ease-out, elastic-ease-in-outbounce-ease-in
In the article it is difficult to describe the differences between these values, or specifically written code, in the browser to see the effect bar.
<script>
Shape.transitionto ({
x:100,
Duration:1,
easing: ' ease-out '
});
</script>
7.3. Callback method after transformation is completed
The config parameter in the kinetic Transitionto (config) method also includes a callback method property, which is executed after the transformation is complete.
<script>
Shape.transitionto ({
x:100,
Duration:1,
easing: "Bounce-ease-out",
callback: function() {
Alert ("Transition complete!" );
}
});
</script>
7.4. Start and end of transformation
When executing The Transitionto method, you can return an object variable and use the start (), Stop (), and resume () Methods of the object to start, stop, and resume the execution of the transformation.
<script>
var trans = Shape.transitionto (config);
Start Conversion
Trans.start ();
Stop Conversion
trans.stop ();
Restore Conversion
Trans.resume ();
</script>