罗盘旋转javascript角度问题 - 旋转/平移 [英] Compass spinning javascript problem with angle - rotate/translate
问题描述
我正在为 iphone 构建一个指南针,呃,只是为了实验目的,并学习如何使用 javascript 和 phonegap 进行操作.
i'm building a compass for the iphone, duh, just for experiment purpose and to learn how to do it, in javascript, with phonegap.
现在我已经能够获得度数,我能够使用 webkit-transform translateZ(或者我可以使用旋转)将 0-360 度应用于 div(我们称之为轮")
now i'm already able to get the degrees, i was able to apply the deg 0-360 to a div (let's call it the "wheel") using the webkit-transform translateZ (or i could use rotate)
但我有一个错误:
当轮子从 0deg 转到 359deg 时一切正常,但是当度数再次变为 0deg 时,它不是在那个方向(顺时针)平稳旋转,而是再次逆时针快速旋转到 positin 0deg...
when the wheel goes from 0deg to 359deg everything is ok, but when the degree goes to 0deg again, instead of smoothly spin in that direction (clockwise), it spin rapidly again anti-clockwise to the positin 0deg...
我不知道我是否清楚,因为没有例子就不容易解释......'
i dont know i'm clear because is not easy to explain without an example....'
基本上我的问题是找到正确的脚本来移动从 0-360 开始的轮子,我可以从 iphone 轻松获得.
basically my problem is to find the right script to move the wheel starting with the value 0-360 that i can get easily from the iphone.
欢迎提出任何建议.
推荐答案
我没有看到任何发表评论的按钮...抱歉,我必须在这里写...这是我的代码
i dont see any button to make comments...sorry but i have to write here... this is my code
deg 是 iphone 给我的值,它可以是 0 到 360.
deg is the value that the iphone give to me ant it can 0 to 360.
document.getElementById('mycompass').style.webkitTransform = "rotateZ("+-deg+"deg)";
document.getElementById('mycompass').style.webkitTransform = "rotateZ("+-deg+"deg)";
当mycompass"转到 359 然后转到 0 时,它会一直向后旋转...
when 'mycompass' goes to 359 and then 0, it rotates all way back...
在你的例子中,我可以有大于 360 的值,所以它对我不起作用......
in you example i can have values bigger than 360 so it doesn't work for me...
我的错误在哪里?
这篇关于罗盘旋转javascript角度问题 - 旋转/平移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!