項目文件結構截圖
只需要一個html文件既可:
項目截圖:
代碼實現原理:
該示例的實現過程很簡單,主要是使用了CSS3的透視、3D旋轉、位移、漸變、陰影,可以說是一次比較全面的練習。
HTML部分:
<div class="wrapper">
<div class="ball"></div>
<div class="stage">
<div class="text">
這里是文字
</div>
</div>
</div>
CSS部分:
使用到的CSS屬性用法:
舞台:
* {
margin: 0;
padding: 0;
}
.wrapper {
width: 400px;
height: 400px;
margin: 200px;
perspective: 800px;
perspective-origin: 50% 50%;
position: relative;
}
.stage {
transform-style: preserve-3d;
position: absolute;
top: 50%;
left: 50%;
transform: translate3d(-50%, -50%, 0);
}
球體:
.ball {
width: 200px;
height: 200px;
border-radius: 50%;
background-color: #ccc;
position: absolute;
top: 50%;
left: 50%;
transform: translate3d(-50%, -50%, 0);
box-shadow: 0px 55px 45px -38px rgba(0, 0, 0, .3);
}
.ball::before {
content: "";
position: absolute;
top: 1%;
left: 5%;
width: 90%;
height: 90%;
border-radius: 50%;
background: -webkit-radial-gradient(50% 0px, circle, #ffffff, rgba(255, 255, 255, 0) 58%);
z-index: 2;
}
文字:
.text {
width: 100px;
height: 50px;
line-height: 50px;
text-align: center;
white-space: nowrap;
animation: rotate 5s linear infinite;
backface-visibility: hidden;
}
文字動畫:
@keyframes rotate {
from {
transform: rotateY(0deg) translateZ(100px);
}
to {
transform: rotateY(360deg) translateZ(100px);
}
}
效果預覽
效果地址:rotate-text-around-the-ballCSS環繞球體的旋轉文字-3D效果
注:本文著作權歸作者,由demo大師代發,拒絕轉載,轉載需要作者授權