[英]Animate needle movement in Gauge chart
I'm using the solution here to plot a speedometer gauge. 我在这里使用解决方案来绘制车速表。 This is built with Flot charts.
这是用Flot图表构建的。 I'm trying to animate the movement of the needle.
我正在尝试设置针的运动动画。 I want the needle to move slowly from start to end.
我希望针头从头到尾缓慢移动。
Here is what I have so far. 这是我到目前为止所拥有的。
updatePlot = function(actual_length){
var data = [[0,0],positionOnArc(actual_length * 100)];
$('.gauge-div').delay( 8000 ).plot([data], options);
}
//The logic: devide one move into 25 moves and add a delay between each move
var diff_length = Math.abs(prev_move_length - move_length) / 25;
for(var i=0; i<25; i++) {
if (prev_move_length < move_length) {
var actual_length = prev_move_length + i * diff_length;
} else {
var actual_length = prev_move_length - i * diff_length;
}
setTimeout(updatePlot(actual_length), 1000);
}
As you can see I'm trying to delay the loop iteration with setTimeout
and delay
. 如您所见,我正在尝试使用
setTimeout
和delay
循环迭代。 But I'm not able to animate the needle movement. 但是我无法为针头运动设置动画。
Can you help me to solve this? 你能帮我解决这个问题吗?
Thanks in Advance. 提前致谢。
There's a clever way to use jquery animate (found here ) by passing in our own step function, which in this case would move the needle. 有一个聪明的方法通过传递我们自己的step函数来使用jquery animate(在此处找到),在这种情况下,它将移动指针。
Sample code: 样例代码:
var updatePlot = function(pos) {
var data = [[0,0],positionOnArc(pos)];
$('#placeholder').plot([data], options);
};
// starting position
updatePlot(0);
$({foo:0}) // from 0 to
.delay(1000) // (wait for it..)
.animate({foo:100}, { // 100
step: updatePlot,
duration: 4300 // in 4.3 seconds
}).animate({foo:0}, { // and back to 0
step: updatePlot,
duration: 1000 // in 1 second
});
Fiddle: http://jsfiddle.net/YGcYJ/217/ 小提琴: http : //jsfiddle.net/YGcYJ/217/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.