像指南针一样旋转时的旋转 webkit 问题

发布于 2024-08-23 14:05:40 字数 605 浏览 10 评论 0原文

这是我的简单函数(“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

慕巷 2024-08-30 14:05:40

这是我的解决方法,但当车轮度数 == -360 或 360 时我仍然遇到问题

var angle = 0;
var lastAngle = 0;




   function watchCompass() {

          var suc = function(a){
          var angle = roundNyc(a.magneticHeading);

       l1 = angle -  lastAngle;
       l2 = 360 - l1;

      if( Math.abs(l1) >=  Math.abs(l2)){ 

       r =   (lastAngle - l2) ; 

      }else{

       r =  angle ; 

      }    

       lastAngle = r;     
       l1 = 0;
       l2 = 0;

   document.getElementById('mycompass').style.webkitTransform = 'rotateZ(' + -r + 'deg)';

          };
          var fail = function(){};
          var opt = {};
          opt.frequency = 50;
          timer = navigator.compass.watchHeading(suc,fail,opt);
        } 

this is my workaround but i stil have problem when the wheel degree == -360 or 360

var angle = 0;
var lastAngle = 0;




   function watchCompass() {

          var suc = function(a){
          var angle = roundNyc(a.magneticHeading);

       l1 = angle -  lastAngle;
       l2 = 360 - l1;

      if( Math.abs(l1) >=  Math.abs(l2)){ 

       r =   (lastAngle - l2) ; 

      }else{

       r =  angle ; 

      }    

       lastAngle = r;     
       l1 = 0;
       l2 = 0;

   document.getElementById('mycompass').style.webkitTransform = 'rotateZ(' + -r + 'deg)';

          };
          var fail = function(){};
          var opt = {};
          opt.frequency = 50;
          timer = navigator.compass.watchHeading(suc,fail,opt);
        } 
瀞厅☆埖开 2024-08-30 14:05:40

同样,这里是如何执行此操作的示例:http://gutfullofbeer.net/compass.html

Again, here is an example of how to do this: http://gutfullofbeer.net/compass.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文