In order to get a ball moving in 3D I have created a new container to contain the image and rotated the container.
The java code is:
//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);
}
}
});
The CSS3 is:
.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);
}
}
This gets a movement in 3D. However, at the end of the animation the ball returns to where it started. I do not want this. The ball starts in the lower right of the container and I want to rotate the container in x, y, z axis so the ball ends up in the top left corner and then keep it there.
Regards,
Glyn