UI and functionality are two important factors for a good product, and many products tend to focus only on functional design and ignore the UI. In this "look-face" era, even if the product is very powerful, if the UI can not keep up with the pace, your products will be greatly discounted in the customer's mind.
The security and monitoring of the project is often scanned, usually using a GIF image to indicate that the software is scanning, but if you want to change the style of the icon, you need to re-do the artwork. Twaver provides animation effect, if the animation style of the icon is not satisfied, can be achieved through a simple change program, to avoid the art of two rework, improve efficiency. Cut to the chase, see how we implement an animated radar scan, first register a picture, with HTML5 canvas to draw a static radar chart, if you are familiar with Twaver, the code below should not be difficult. If you are unfamiliar, you can refer to the product documentation custom drawing (Draw) section.
?
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 6667 |
twaver.Util.registerImage(‘radar‘, {
v: [
{
shape: ‘draw‘,
draw: function (ctx, data, view) {
var canvas = this.canvas,
g = this.g,
gradient = this.gradient,
diameter = Math.floor(data.getWidth() * view.getZoom()),
radius = diameter / 2,
hueStart = 120,
hueEnd = 170,
hueDiff = Math.abs(hueEnd - hueStart),
width = diameter,
height = diameter;
if (!canvas) {
this.canvas = canvas = document.createElement(‘canvas‘);
}
if (width !== canvas.width || height !== canvas.height) {
canvas.width = diameter;
canvas.height = diameter;
this.g = g = canvas.getContext(‘2d‘);
this.gradient = gradient = g.createLinearGradient(radius, 0, 0, 0);
gradient.addColorStop(0, ‘hsla(‘ + hueStart + ‘, ‘ + 50 + ‘%, ‘ + 40 + ‘%, 1)‘);
gradient.addColorStop(1, ‘hsla(‘ + hueEnd + ‘, ‘ + 50 + ‘%, ‘ + 40 + ‘%, 0.1)‘);
}
g.globalCompositeOperation = ‘destination-out‘;
g.fillStyle = ‘hsla(0, 0%, 0%, 0.1)‘;
g.fillRect(0, 0, width, height);
g.globalCompositeOperation = ‘lighter‘;
var i;
for (i = 0; i < 4; i++) {
g.beginPath();
g.arc(radius, radius, ((radius - 1) / 4) * (i + 1), 0, Math.PI * 2, false);
g.strokeStyle = ‘hsla(‘ + (hueEnd - (i * (hueDiff / 4))) + ‘, ‘ + 50 + ‘%, ‘ + 40 + ‘%, 0.1)‘;
g.lineWidth = 3;
g.stroke();
};
g.beginPath();
g.moveTo(radius - 1, 2);
g.lineTo(radius - 1, height - 2);
g.moveTo(2, radius - 1);
g.lineTo(width - 2, radius - 1);
g.strokeStyle = ‘hsla(‘ + ((hueStart + hueEnd) / 2) + ‘, ‘ + 50 + ‘%, ‘ + 40 + ‘%, .03)‘;
g.stroke();
g.save();
g.translate(radius, radius);
g.rotate(data.getClient(‘angle‘));
g.beginPath();
g.moveTo(0, 0);
g.arc(0, 0, radius, -0.0349, 0.0349, false);
g.closePath();
g.fillStyle = gradient;
g.fill();
g.restore();
ctx.scale(1 / view.getZoom(), 1 / view.getZoom());
ctx.drawImage(canvas, -width / 2, -height / 2);
}
}
]
});
|
Next, set a dynamic effect on the radar chart, allowing radar to scan continuously. This code below sets the scanning angle of the radar pointer, duration:
?
12345678910 |
new twaver.Animate({
source: node,
attr: ‘[email protected]‘,
from: 0,
to: Math.PI * 2,
dur: 4000,
repeat: Number.POSITIVE_INFINITY,
reverse: false
}).play();
}
|
Such a simple radar animation effect is out, is not very simple answer, if the effect of interest, you can send email request source code, attached email: [Email protected]
Radar scanning effect of twaver animation