【问题标题】:How to check the transform rotate with if in js如何在js中使用if检查变换旋转
【发布时间】:2022-05-10 21:22:01
【问题描述】:

如果使用 java 脚本,如何检查变换旋转?

getComputedstyle

【问题讨论】:

    标签: javascript html css


    【解决方案1】:

    这里是获取变换属性的示例...
    这个问题是,你不会得到像 30deg 这样的东西作为从变换返回的东西,或者你得到一个矩阵......
    这可以转换回你的度数->我想你最后想知道;)

    further information about matrix and calculation

    here 用于从矩阵中获取学位的在线计算器

    var rotateStyle = window.getComputedStyle(document.querySelector('.rotate'), null);
    
    alert(rotateStyle.transform);
    .rotate {
      display: inline-block;
      transform: rotate(-90deg);
    }
    <span class="rotate">‹3</span>

    【讨论】:

      【解决方案2】:

      http://jsfiddle.net/ax5nM/108/ 中使用了box 类——直到现在用于检查translateX

      var t=$(".box").css('transform').split(/[()]/)[1].split(',');
      

      但也使矩阵的属性可访问。

      矩阵代表的一些例子可以在这里找到:https://www.w3schools.com/cssref/playit.asp?filename=playcss_transform_matrix

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-06-20
        • 2020-02-03
        • 1970-01-01
        • 2017-09-24
        • 2021-02-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多