function driveTo(new_value){
pre_value = document.getElementById("pre_value").value;
var arc_params = {
center: [180,180],
radius: 180,
start: pre_value,
end: new_value,
dir: -1
}
$(".car").animate({path : new $.path.arc(arc_params)})
document.getElementById("pre_value").value = new_value;
}
这个尝试存在一个问题...如果绿点在90度,你点击270度会出现一些我不理解的疯狂行为,但最终仍会停在正确的位置?!还有我的第二个: Fiddle two
function driveTo(new_value){
pre_value = document.getElementById("pre_value").value;
// catch if the new position is bigger than the previous one
if (new_value > pre_value) {
var arc_params = {
center: [180,180],
radius: 180,
start: pre_value,
end: 0,
dir: -1
}
$(".car").animate({path : new $.path.arc(arc_params)})
var arc_params = {
center: [180,180],
radius: 180,
start: 0,
end: new_value,
dir: -1
}
$(".car").animate({path : new $.path.arc(arc_params)})
}
else{
var arc_params = {
center: [180,180],
radius: 180,
start: pre_value,
end: new_value,
dir: -1
}
$(".car").animate({path : new $.path.arc(arc_params)})
}
document.getElementById("pre_value").value = new_value;
}
在这个版本中,我试图通过检查新值是否大于先前的值来解决我在第一个命题中遇到的问题。如果是真的,对象必须首先到达位置0,然后继续到新值。但是,问题在于显然当物体到达零时会减速,然后再次加速以达到原始目标。
我认为这不是很好...我希望我可以避免这种情况!
我正在使用jQuery arc path plugin,但关于它的文档非常少...
有什么建议吗?
更新
这里有一个更好的fiddle,基于形状需要行进的距离,具有实际的线性速度。甚至还有一个可以设置的速度因素:)