Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
211 views
in Technique[技术] by (71.8m points)

Rotating in the Y direction css

Trying to make a logo rotate in the Y direction as so :

@keyframes rotateLogo {
  0% {
    transform: rotateY(0deg)
  }
  // 50% {
  //   transform: rotateY(180deg)
  // }
  100% {
    transform: rotateY(360deg)
  }
}

.splashAnimation{
  animation-name: rotateLogo;
  animation-duration: 3s;
  animation-iteration-count: infinite;
  animation-timing-function: linear;
}

However it ends up looking like this:

https://giphy.com/gifs/g0gEjkRZ5lLI3mLBDo

Thanks for reading, will post a jsbin but i imagine this is a known issue.

JSBIN: https://jsbin.com/yihoriniso/edit?html,css,output


EDIT: This seems to happen as described because of an optical illusion. Is there any way to provide perspective in the rotation so as to provide some cues to the brain to perceive the rotation as unidirectional?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to add perspective to your logo's parent element in order to get the '3d' feel to it, like so:

body {
  perspective: 800px;
  background-color: #eee;
}

@keyframes rotateLogo {
  0% {
    transform: rotateY(0deg)
  }
  100% {
    transform: rotateY(360deg)
  }
}

.splashAnimation{
  animation-name: rotateLogo;
  animation-duration: 3s;

  animation-iteration-count: infinite;
  /* animation-timing-function: linear; */
}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>it works here..</title>
</head>
<body>
  
  <div class="splashAnimation" style="height:100%;display:flex;align-items:center;justify-content:center">
    <img style="width:100px;height:100px" src="http://brandmark.io/logo-rank/random/beats.png">
  </div>
  

</body>
</html>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...