像指南针一样旋转时的旋转 webkit 问题
这是我的简单函数(“mycompass”是我体内的一个 div),
function watchCompass() {
var suc = function(a){
var r =a.magneticHeading;
document.getElementById('mycompass').style.webkitTransform = "rotateZ("+-r+"deg)";
};
var fail = function(){};
var opt = {};
opt.frequency = 50;
timer = navigator.compass.watchHeading(suc,fail,opt);
}
出于某种原因,当罗盘“轮”从 0 到 360 进行完整旋转时,它会返回到 0 而不是“虚拟”361...等等..无法理解从0到360没有区别...
而且我不知道如何计算一种方法让轮子顺时针和逆时针旋转平滑地
提出这个问题的另一种方法是:
我怎样才能例如,将我的对象从 15 度旋转到 270 度,逆时针方向而不是顺时针方向?我怎样才能告诉我的脚本那个值?
this is my simple function ('mycompass' is a div in my body)
function watchCompass() {
var suc = function(a){
var r =a.magneticHeading;
document.getElementById('mycompass').style.webkitTransform = "rotateZ("+-r+"deg)";
};
var fail = function(){};
var opt = {};
opt.frequency = 50;
timer = navigator.compass.watchHeading(suc,fail,opt);
}
for some reason when the compass 'wheel' does a complete rotation from 0 to 360 it goes back to 0 and not to the "virtual" 361... etc.. is not able to understand that from 0 and 360 there is no difference ...
and I don't know how to calculate a way to have the wheel spining smoothy clockwise and anticlockwise
another way to put this question is:
how can i rotate my objext from, for instance, from 15deg to 270deg, in anti-clockwise direction instead of clockwise? how can i tell my script that vale?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我的解决方法,但当车轮度数 == -360 或 360 时我仍然遇到问题
this is my workaround but i stil have problem when the wheel degree == -360 or 360
同样,这里是如何执行此操作的示例:http://gutfullofbeer.net/compass.html
Again, here is an example of how to do this: http://gutfullofbeer.net/compass.html