【问题标题】:How to stop an image returning to its starting point using CSS3 rotate3d如何使用 CSS3 rotate3d 停止图像返回其起点
【发布时间】:2014-12-27 07:48:41
【问题描述】:

为了让球在 3D 中移动,我创建了一个新容器来包含图像并旋转容器。

java代码是:

//Run the play when the "Play Ball" button is selected.
        runButton.addClickHandler(new ClickHandler()
        {
            public void onClick(ClickEvent event) {   

                if (play == 1) {

                    //play1();
                    moveBallContainer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
                    moveBallContainer.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);

                    moveBallContainer.add(img);
                    absolutePanel.add(moveBallContainer, 5, 200);
                    moveBallContainer.addStyleName("roundBall3DMove");
                    answerTextBox1.setCursorPos(0);

                }  
            }
        });

CSS3 是:

.roundBall3DMove {
    width: 295px;
    height: 220px;
    position: relative;
    background: grey; /* So I can see what is happening - remove */
    border-radius: 0px;
    perspective: 500px;
    -webkit-animation-name: roundBall3DMove;
    -webkit-animation-timing-function: linear;
    -webkit-animation-iteration-count: 1;
    -webkit-animation-duration: 2s;

    -webkit-animation-fill-mode: forwards; /* Chrome, Safari, Opera */
    animation-fill-mode: forwards;

    animation-name: roundBall3DMove;
    animation-timing-function: linear;
    animation-iteration-count: 1;
    animation-duration: 2s;

    -webkit-transform-style: preserve-3d;
    -moz-transform-style: preserve-3d;
    -ms-transform-style: preserve-3d;
    transform-style: preserve-3d;
  }

  .roundBall3DMove:hover {
    -webkit-animation-play-state: paused;
    animation-play-state: paused;
  }

/* Chrome, Safari, Opera */
@-webkit-keyframes roundBall3DMove {
    from { -webkit-transform: rotate3d(1, 0, 0, 0deg) rotate3d(0, 1, 0, 0deg) rotate3d(0, 0, 1, 0deg); }
    to   { -webkit-transform: rotate3d(1, 0, 0, 180deg) rotate3d(0, 1, 0, 180deg) rotate3d(0, 0, 1, 180deg); }
 }

 /* all other browsers */
  @keyframes roundBall3DMove {
    from {
      -moz-transform: rotate3d(1, 0, 0, 0deg) rotate3d(0, 1, 0, 0deg) rotate3d(0, 0, 1, 0deg);
      -ms-transform: rotate3d(1, 0, 0, 0deg) rotate3d(0, 1, 0, 0deg) rotate3d(0, 0, 1, 0deg);
      transform: rotate3d(1, 0, 0, 0deg) rotate3d(0, 1, 0, 0deg) rotate3d(0, 0, 1, 0deg);
    }
    to {
      -moz-transform: rotate3d(1, 0, 0, 180deg) rotate3d(0, 1, 0, 180deg) rotate3d(0, 0, 1, 180deg);
      -ms-transform: rotate3d(1, 0, 0, 180deg) rotate3d(0, 1, 0, 180deg) rotate3d(0, 0, 1, 180deg);
      transform: rotate3d(1, 0, 0, 180deg) rotate3d(0, 1, 0, 180deg) rotate3d(0, 0, 1, 180deg);
    }
  }

这会产生 3D 运动。然而,在动画结束时,球会回到它开始的地方。我不想要这个。球从容器的右下角开始,我想在 x、y、z 轴上旋转容器,使球在左上角结束,然后保持在那里。

问候,

格林

【问题讨论】:

    标签: css


    【解决方案1】:

    经过大量摆弄后,我发现如果我调整 x 轴 "rotate3d(0, 0, 1, 180deg);"到,例如“rotate3d(0, 0, 1, 45deg); 则不会回到原来的位置。

    问候,格林

    【讨论】:

      【解决方案2】:

      您需要添加 animation-fill-mode 属性并将其设置为转发。 animation-fill-mode 属性接受: 动画将在动画结束时应用属性值的位置;向后应用将开始动画第一次迭代的关键帧中定义的属性值;和两者,这将遵守向前和向后的规则。

      -webkit-animation-fill-mode:forwards;
      -moz-animation-fill-mode:forwards;
      animation-fill-mode:forwards;
      

      请注意,低于 2.3 的 Android 浏览器不支持此属性。有关支持的更多信息,请参阅:http://caniuse.com/#feat=css-animation

      【讨论】:

      • 嗨@jme11,我已经有了“animation-fill-mode:forwards;”。但是,非常感谢您的回答,我非常感谢您的努力。我会继续实验。问候,格林
      • 是的,我现在明白了。抱歉,不知怎的,我之前错过了。
      • 嗨@jme11,经过大量摆弄后,我发现如果我调整x轴“rotate3d(0, 0, 1, 180deg);”例如,“rotate3d(0, 0, 1, 45deg); 然后它不会返回到原始位置。问候,Glyn
      • 太棒了。很高兴知道。例如,我在使用 270deg 时看到过类似的意外副作用,但在这种情况下从未见过。为了他人的利益,您应该发布答案并将其标记为已接受。感谢分享。
      • 嗨@jme11,是的,我已经发布并标记了。我还有很多事情要做。所以我将进行实验和发布。但是,我正在学习和享受这一点。所以谢谢。问候,格林
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-07
      • 2021-12-10
      • 1970-01-01
      相关资源
      最近更新 更多