我想通过速度js旋转元素,但rotateZ不起作用,但是某些动画(如宽度,高度,不透明度等)可以正常工作。

这是我的简单代码:

<style>
    #test{
      height: 100px;
      width: 10px;
      background-color: red;
    }
</style>
<body>
    <div id="test"></div>

    <script src="jquery-3.3.1.js"></script>
    <script src="velocity.min.js"></script>
    <script>

        var value = 360; //animate to
        var steps = 6; //animation steps per frame (1/60sec.)
        var time = (1000 / 60) * (value / steps); //animation time

        $('#test').velocity({
            rotateZ: "360deg"
        }, { delay: 400, duration: 1000, easing: 'linear', loop: true });

    </script>
</body>


有什么特别的我要忽略的地方吗?

最佳答案

V2不再支持rotateZ
https://github.com/julianshapiro/velocity/blob/master/V2_CHANGES.md

1.5.1可以正常工作。查看下面Rycochet中的答案以在V2中实现这一目标。



#test{
  height: 100px;
  width: 10px;
  background-color: red;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/velocity/1.5.1/velocity.min.js"></script>
<body>
    <div id="test"></div>
    <script>

        var value = 360; //animate to
        var steps = 6; //animation steps per frame (1/60sec.)
        var time = (1000 / 60) * (value / steps); //animation time

        $('#test').velocity({
            rotateZ: "360deg"
        }, { delay: 400, duration: 1000, easing: 'linear', loop: true });

    </script>
</body>

关于javascript - 简单的rotateZ在Velocity js中不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49963104/

10-09 16:47