利用 CSS 3D 实现星空穿梭效果
perspective
值下,设定容器的 translateZ
动画,实现效果<div class="g-container"><div class="g-group"><div class="item item-right"></div><div class="item item-left"></div> <div class="item item-top"></div><div class="item item-bottom"></div> <div class="item item-middle"></div> </div><div class="g-group"><div class="item item-right"></div><div class="item item-left"></div> <div class="item item-top"></div><div class="item item-bottom"></div> <div class="item item-middle"></div> </div>
</div>
CSS:
html, body{height: 100%;width: 100%;overflow: hidden;background: #000;text-align: center;
}body:before{content: '';display: inline-block;height: 100%;vertical-align: middle;
}.g-container{display: inline-block;vertical-align: middle;perspective: 4px;perspective-origin: 50% 50%;position: relative;animation: hueRotate 21s infinite linear;
}.g-group{position: absolute;
/* perspective: 4px; */width: 1000px;height: 1000px;left: -500px;top: -500px;transform-style: preserve-3d;animation: move 12s infinite linear;animation-fill-mode: forwards;
}.g-group:nth-child(2){animation: move 12s infinite linear;animation-delay: -6s;
}.item {position: absolute;width: 100%;height: 100%;background: url(.jpg);background-size: cover;opacity: 1;animation: fade 12s infinite linear;animation-delay: 0;
}.g-group:nth-child(2) .item {animation-delay: -6s;
}.item-right {transform: rotateY(90deg) translateZ(500px);
}.item-left {transform: rotateY(-90deg) translateZ(500px);
}.item-top {transform: rotateX(90deg) translateZ(500px);
}.item-bottom {transform: rotateX(-90deg) translateZ(500px);
}.item-middle {transform: rotateX(180deg) translateZ(1000px);
}@keyframes move {0%{transform: translateZ(-500px) rotate(0deg);}100%{transform: translateZ(500px) rotate(0deg);}
}@keyframes fade {0%{opacity: 0;}25%,60%{opacity: 1;}100%{opacity: 0;}
}@keyframes hueRotate {0% {filter: hue-rotate(0);}100% {filter: hue-rotate(360deg);}
}
效果如下:C
本文发布于:2024-02-04 14:33:01,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170709429856399.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |