html实现颜色刷新变化,CSS实现的色彩动态变化效果

此博客展示了如何使用CSS3 SCSS实现一个3D旋转立方体效果,通过`-webkit-box`和`transform`属性结合关键帧动画,创建了逐个缩放并旋转的立方体,同时配合颜色变化和延迟动画,展示视觉层次感。
摘要由CSDN通过智能技术生成

CSS

语言:

CSSSCSS

确定

body {

margin: 0;

display: -webkit-box;

display: -webkit-flex;

display: -ms-flexbox;

display: flex;

-webkit-box-align: center;

-webkit-align-items: center;

-ms-flex-align: center;

align-items: center;

-webkit-box-pack: center;

-webkit-justify-content: center;

-ms-flex-pack: center;

justify-content: center;

height: 100vh;

overflow: hidden;

background: black;

}

.view {

position: relative;

height: 600px;

width: 900px;

-webkit-box-flex: 0;

-webkit-flex: 0 0 900px;

-ms-flex: 0 0 900px;

flex: 0 0 900px;

}

.axis {

position: absolute;

top: 0;

right: 0;

bottom: 0;

left: 0;

display: -webkit-box;

display: -webkit-flex;

display: -ms-flexbox;

display: flex;

-webkit-transform: rotateX(-35deg) rotateY(45deg);

transform: rotateX(-35deg) rotateY(45deg);

}

.axis,

.axis * {

-webkit-transform-style: preserve-3d;

transform-style: preserve-3d;

}

.cube {

position: absolute;

top: 50%;

left: 50%;

height: 50px;

width: 50px;

margin: -25px;

will-change: transform, visibility;

}

.cube:nth-child(3) {

-webkit-transform: scaleY(0) translateY(0%);

transform: scaleY(0) translateY(0%);

-webkit-transform-origin: 50% 0%;

transform-origin: 50% 0%;

-webkit-animation: outer 3s linear infinite;

animation: outer 3s linear infinite;

margin-top: -125px;

}

.cube:nth-child(2) {

-webkit-transform: scaleY(0);

transform: scaleY(0);

-webkit-transform-origin: 50% 50%;

transform-origin: 50% 50%;

-webkit-animation: center 3s linear infinite alternate;

animation: center 3s linear infinite alternate;

}

.cube:nth-child(1) {

-webkit-transform: scaleY(0);

transform: scaleY(0);

-webkit-transform-origin: 50% 100%;

transform-origin: 50% 100%;

-webkit-animation: outer 3s linear infinite alternate;

animation: outer 3s linear infinite alternate;

margin-top: 75px;

}

@-webkit-keyframes outer {

0%, 5% {

-webkit-transform: scaleY(0.5);

transform: scaleY(0.5);

}

50% {

-webkit-transform: scaleY(2.5);

transform: scaleY(2.5);

}

95%,

100% {

-webkit-transform: scaleY(0.5);

transform: scaleY(0.5);

}

}

@keyframes outer {

0%, 5% {

-webkit-transform: scaleY(0.5);

transform: scaleY(0.5);

}

50% {

-webkit-transform: scaleY(2.5);

transform: scaleY(2.5);

}

95%,

100% {

-webkit-transform: scaleY(0.5);

transform: scaleY(0.5);

}

}

@-webkit-keyframes center {

0%, 5%, 50% {

-webkit-transform: scaleY(0);

transform: scaleY(0);

visibility: hidden;

}

95%,

100% {

-webkit-transform: scaleY(4);

transform: scaleY(4);

visibility: visible;

}

}

@keyframes center {

0%, 5%, 50% {

-webkit-transform: scaleY(0);

transform: scaleY(0);

visibility: hidden;

}

95%,

100% {

-webkit-transform: scaleY(4);

transform: scaleY(4);

visibility: visible;

}

}

.cube .side {

position: absolute;

top: 0;

right: 0;

bottom: 0;

left: 0;

background-color: currentColor;

}

.cube .side:nth-child(1) {

-webkit-transform: translateZ(25px);

transform: translateZ(25px);

background-image: -webkit-linear-gradient(rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.4));

background-image: linear-gradient(rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.4));

}

.cube .side:nth-child(2) {

-webkit-transform: rotateY(-90deg) translateZ(25px);

transform: rotateY(-90deg) translateZ(25px);

background-image: -webkit-linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.7));

background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.7));

}

.cube .side:nth-child(3) {

-webkit-transform: rotateX(90deg) translateZ(25px);

transform: rotateX(90deg) translateZ(25px);

background-image: -webkit-linear-gradient(transparent, rgba(0, 0, 0, 0.2));

background-image: linear-gradient(transparent, rgba(0, 0, 0, 0.2));

}

.collection {

display: inline-block;

height: 100%;

width: 50px;

margin: 0 12.5px;

}

.collection:nth-child(1) {

z-index: 12;

}

.collection:nth-child(1) .cube {

-webkit-animation-delay: 0s;

animation-delay: 0s;

}

.collection:nth-child(1) .cube:nth-child(1) {

color: #9efafa;

}

.collection:nth-child(1) .cube:nth-child(2) {

color: #ccfa9e;

}

.collection:nth-child(1) .cube:nth-child(3) {

color: #fa9e9e;

}

.collection:nth-child(2) {

z-index: 11;

}

.collection:nth-child(2) .cube {

-webkit-animation-delay: -0.25s;

animation-delay: -0.25s;

}

.collection:nth-child(2) .cube:nth-child(1) {

color: #9eccfa;

}

.collection:nth-child(2) .cube:nth-child(2) {

color: #9efa9e;

}

.collection:nth-child(2) .cube:nth-child(3) {

color: #facc9e;

}

.collection:nth-child(3) {

z-index: 10;

}

.collection:nth-child(3) .cube {

-webkit-animation-delay: -0.5s;

animation-delay: -0.5s;

}

.collection:nth-child(3) .cube:nth-child(1) {

color: #9e9efa;

}

.collection:nth-child(3) .cube:nth-child(2) {

color: #9efacc;

}

.collection:nth-child(3) .cube:nth-child(3) {

color: #fafa9e;

}

.collection:nth-child(4) {

z-index: 9;

}

.collection:nth-child(4) .cube {

-webkit-animation-delay: -0.75s;

animation-delay: -0.75s;

}

.collection:nth-child(4) .cube:nth-child(1) {

color: #cc9efa;

}

.collection:nth-child(4) .cube:nth-child(2) {

color: #9efafa;

}

.collection:nth-child(4) .cube:nth-child(3) {

color: #ccfa9e;

}

.collection:nth-child(5) {

z-index: 8;

}

.collection:nth-child(5) .cube {

-webkit-animation-delay: -1s;

animation-delay: -1s;

}

.collection:nth-child(5) .cube:nth-child(1) {

color: #fa9efa;

}

.collection:nth-child(5) .cube:nth-child(2) {

color: #9eccfa;

}

.collection:nth-child(5) .cube:nth-child(3) {

color: #9efa9e;

}

.collection:nth-child(6) {

z-index: 7;

}

.collection:nth-child(6) .cube {

-webkit-animation-delay: -1.25s;

animation-delay: -1.25s;

}

.collection:nth-child(6) .cube:nth-child(1) {

color: #fa9ecc;

}

.collection:nth-child(6) .cube:nth-child(2) {

color: #9e9efa;

}

.collection:nth-child(6) .cube:nth-child(3) {

color: #9efacc;

}

.collection:nth-child(7) {

z-index: 6;

}

.collection:nth-child(7) .cube {

-webkit-animation-delay: -1.5s;

animation-delay: -1.5s;

}

.collection:nth-child(7) .cube:nth-child(1) {

color: #fa9e9e;

}

.collection:nth-child(7) .cube:nth-child(2) {

color: #cc9efa;

}

.collection:nth-child(7) .cube:nth-child(3) {

color: #9efafa;

}

.collection:nth-child(8) {

z-index: 5;

}

.collection:nth-child(8) .cube {

-webkit-animation-delay: -1.75s;

animation-delay: -1.75s;

}

.collection:nth-child(8) .cube:nth-child(1) {

color: #facc9e;

}

.collection:nth-child(8) .cube:nth-child(2) {

color: #fa9efa;

}

.collection:nth-child(8) .cube:nth-child(3) {

color: #9eccfa;

}

.collection:nth-child(9) {

z-index: 4;

}

.collection:nth-child(9) .cube {

-webkit-animation-delay: -2s;

animation-delay: -2s;

}

.collection:nth-child(9) .cube:nth-child(1) {

color: #fafa9e;

}

.collection:nth-child(9) .cube:nth-child(2) {

color: #fa9ecc;

}

.collection:nth-child(9) .cube:nth-child(3) {

color: #9e9efa;

}

.collection:nth-child(10) {

z-index: 3;

}

.collection:nth-child(10) .cube {

-webkit-animation-delay: -2.25s;

animation-delay: -2.25s;

}

.collection:nth-child(10) .cube:nth-child(1) {

color: #ccfa9e;

}

.collection:nth-child(10) .cube:nth-child(2) {

color: #fa9e9e;

}

.collection:nth-child(10) .cube:nth-child(3) {

color: #cc9efa;

}

.collection:nth-child(11) {

z-index: 2;

}

.collection:nth-child(11) .cube {

-webkit-animation-delay: -2.5s;

animation-delay: -2.5s;

}

.collection:nth-child(11) .cube:nth-child(1) {

color: #9efa9e;

}

.collection:nth-child(11) .cube:nth-child(2) {

color: #facc9e;

}

.collection:nth-child(11) .cube:nth-child(3) {

color: #fa9efa;

}

.collection:nth-child(12) {

z-index: 1;

}

.collection:nth-child(12) .cube {

-webkit-animation-delay: -2.75s;

animation-delay: -2.75s;

}

.collection:nth-child(12) .cube:nth-child(1) {

color: #9efacc;

}

.collection:nth-child(12) .cube:nth-child(2) {

color: #fafa9e;

}

.collection:nth-child(12) .cube:nth-child(3) {

color: #fa9ecc;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值