当前位置:Gxlcms > css > CSS3D实现旋转球是如何实现的?(代码案例)

CSS3D实现旋转球是如何实现的?(代码案例)

时间:2021-07-01 10:21:17 帮助过:54人阅读

本篇文章给大家带来的内容是关于CSS 3D实现旋转球是如何实现的?(代码案例),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

微信截图_20181022141151.png

废话不多说了,直接给大家贴代码了,具体代码如下所示:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset=utf-8 />
  5. <title>zimv-css 3d ball</title>
  6. </head>
  7. <style>
  8. body{
  9. padding: 100px 0 0 150px;
  10. }
  11. </style>
  12. <body>
  13. <p class="wrapper">
  14. <p class="box" id="circles">
  15. </p>
  16. </p>
  17. <style>
  18. .wrapper{
  19. animation: rotate 3s infinite linear alternate;
  20. transform-style: preserve-3d;
  21. width: 100px;
  22. height: 100px;
  23. margin:150px 0 0 150px;
  24. }
  25. .box{
  26. width: 100%;
  27. height: 100%;
  28. position: relative;
  29. transform-style: preserve-3d;
  30. transform: rotateX(-30deg) rotateY(45deg);
  31. }
  32. .circle{
  33. border-radius: 50%;
  34. width: 100%;
  35. height: 100%;
  36. position: absolute;
  37. left: 0;
  38. top: 0;
  39. border: 1px solid red;
  40. }
  41. @keyframes rotate {
  42. 0% {
  43. transform: rotateZ(0deg);
  44. }
  45. 50%{
  46. transform: rotateZ(360deg);
  47. }
  48. 100% {
  49. transform: rotateZ(360deg) rotateX(180deg);
  50. }
  51. }
  52. </style>
  53. <script>
  54. let cir = document.getElementById('circles');
  55. for(let i=0;i<180;i++){
  56. let p = document.createElement('p');
  57. p.style = `transform: rotateX(${i}deg);border: 1px solid rgba(200,200,200,1)`;
  58. p.className = 'circle';
  59. cir.appendChild(p);
  60. }
  61. </script>
  62. </body>
  63. </html>

以上就是对的全部介绍,如果您想了解更多有关CSS视频教程,请关注PHP中文网。

以上就是CSS 3D实现旋转球是如何实现的?(代码案例)的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行