Index
The HT system can dynamically change the properties of model to achieve animation effects by the ht.Default.startAnim function introduces in Beginners Manual, or the DataModel#addScheduleTask function.
The animation plug-in to be introduced in this manual will further encapsulate the animation, the user can only uses descriptive description that HT will automate the animation process, the animation plug-in can be one or more of the attributes of the data values (such as width, height, opacity, etc.) from a value smoothly change to another value, while providing a rich easing method for various effects, such as flashing, jumping, discoloration, etc.
Before using this plug-in, you need to introduce ht-animation.js file:
<script src="ht.js"></script> <!--Introduce ht.js file first-->
<script src="ht-animation.js"></script>
To use animations, you need to call ht.DataModel#enableAnimation(interval) to start global animation timer first, parameter interval specifies the global animation interval, the default is requestAnimFrame time (16ms around, browser-specific), in other words, if you do not specify interval parameters, DataModel timer will traverse all of their Data in every 16ms, according to Data animation configuration to perform animation
In addition to enableAnimation, there are two other APIs in DataModel that are often used:
disableAnimation() Stop the global animation timer, if you do not need any animation then please close the timer, otherwise it will cause performance wastegetDataAnimation(data) Gets the animation configuration of the parameter data, if you do not want to specify the animation parameter for each Data, but rather want to generate an animation configuration based on the Data category or identity, you can override this method implementation (reference Example II)This plug-in is expands an setAnimation(config) function based in ht.Data to configure the animation settings for the current data, and a simple configuration example is as follows:
data.setAnimation({
show: {
property: "opacity",
accessType: "style",
from: 1,
to: 0,
repeat: true
},
start: ["show"]
});
As you can see, the parameter config is a js object in which you can define one or more animation processes with any string other than start in particular meaning
The configuration above defines an animation process called show, which changes the opacity style (transparency) of the data, and changes it from 1 to 0, repeat means the animation repeats until you call setAnimation(null) clears the animation. Need attention:
After you clear the animation through the API, the property can be in any state, as in the example above, the opacity style can be any number between 0-1, and you may need to reset this style.
start is an array that specifies one or more animations to start, and the example above defines only one animation named show, in fact, you can define as many as you want, and the animation configuration parameters are listed as follows:
property The attribute name of the data that the animation will changeaccessType property type enumeration as follows:null Default type, such as property is for width, using getWidth() and setWidth(value) get/set or is/set mode to access.style Such as property is for width, using getStyle() and setStyle('width', value) mode to access.attr Such as property is for width, using getAttr() and setAttr('width', value) mode to access.from The property value at start of animationto The property value at the end of animationframes Animation frame number, default to 60duration Duration, unit ms; frames and this parameter can only be selected one, can not exist at the same timeinterval Animation interval, unit ms, if not specified then equal to the global animation interval; applicable to the situation that the current data animation interval is inconsistent with the global animation intervaldelay Animation delay execution time, unit msrepeat Specifies whether the animation is performed in loop, and if so, represents the number of times the loopeasing Animation method, enumerated as follows: Linear、Quad.easeIn、Quad.easeOut、 Quad.easeInOut;Cubic.easeIn、Cubic.easeOut、 Cubic.easeInOut;
Quart.easeIn、Quart.easeOut、 Quart.easeInOut;Quint.easeIn、Quint.easeOut、 Quint.easeInOut;Sine.easeIn、Sine.easeOut、 Sine.easeInOut;
Expo.easeIn、Expo.easeOut、 Expo.easeInOut;Circ.easeIn、Circ.easeOut、 Circ.easeInOut;Elastic.easeIn、Elastic.easeOut、 Elastic.easeInOut;
Back.easeIn、Back.easeOut、 Back.easeInOut;Bounce.easeIn、Bounce.easeOut、 Bounce.easeInOut
How do these animations differ? Refer to: http://easings.net/
onUpdate: Function (value) Callback function, each frame of the animation will be called back.
onComplete: Function () Callback functions, execution after animation completesnext String type, specifying the next animation to perform after the current animation is complete, you can merge multiple animationsht.Data Supports the following functions for pausing and continuing animations:
pauseAnimation() Pause animationresumeAnimation() Continue to animateNote the configuration of the dyeing data:
node2.setAnimation({
blend: {
from: 255,
to: 0,
next: "clear",
onUpdate: function (value) {
value = parseInt(value);
this.s("body.color", "rgb(255, " + value + ", " + value + ")");
}
},
clear: {
from: 0,
to: 255,
next: "blend",
onUpdate: function (value) {
value = parseInt(value);
this.s("body.color", "rgb(255, " + value + ", " + value + ")");
}
},
start: ["blend"]
});
The start parameter specifies the start of the blend animation, and the dyeing animation has actually been changing the data's body.color style, where we don't specify property and accessType because body.color is not just a numeric type, but a string that represents the RGB color, so we used the onUpdate callback function, each of which combines strings to change the data's body.color
dm.getDataAnimation = function (data) {
if (data.getName() === "node1") {
if (data.getAnimation() != null) {
return data.getAnimation();
} else {
return {
hide: {
property: "opacity",
accessType: "style",
from: 1,
to: 0,
frames: 1,
next: "show"
},
show: {
property: "opacity",
accessType: "style",
from: 0,
to: 1,
frames: 1,
next: "hide"
},
start: ["hide"]
};
}
} else {
return null;
}
};
In this example, we did not call ht.Data#setAnimation, but by rewriting ht.DataModel#getDataAnimation, create an animation configuration based on the name of the data, which is useful in some scenes that require flexible animation
This example demonstrates how to make a dashed line style flow:
This example shows how to blink the data alert icon: