在仪表板设计时,经常需要添加一些动效来提升视觉冲击力,这个帖子主要介滑动的流星。
实现步骤:
1、在仪表板中添加外部扩展
2、将以下代码粘贴到外部扩展的Html视图中,点击确定
- <html>
- <head>
- <style>
- body {
- height: 100vh;
- overflow: hidden;
- display: flex;
- font-family: "Anton", sans-serif;
- justify-content: center;
- align-items: center;
- }
- .night {
- position: relative;
- width: 100%;
- height: 100%;
- transform: rotateZ(45deg);
- }
- .shooting_star {
- position: absolute;
- left: 50%;
- top: 50%;
- height: 2px;
- background: linear-gradient(-45deg, #5f91ff, rgba(0, 0, 255, 0));
- border-radius: 999px;
- filter: drop-shadow(0 0 6px #699bff);
- -webkit-animation: tail 3000ms ease-in-out infinite, shooting 3000ms ease-in-out infinite;
- animation: tail 3000ms ease-in-out infinite, shooting 3000ms ease-in-out infinite;
- }
- .shooting_star::before {
- content: "";
- position: absolute;
- top: calc(50% - 1px);
- right: 0;
- height: 2px;
- background: linear-gradient(-45deg, rgba(0, 0, 255, 0), #5f91ff, rgba(0, 0, 255, 0));
- transform: translateX(50%) rotateZ(45deg);
- border-radius: 100%;
- -webkit-animation: shining 3000ms ease-in-out infinite;
- animation: shining 3000ms ease-in-out infinite;
- }
- .shooting_star::after {
- content: "";
- position: absolute;
- top: calc(50% - 1px);
- right: 0;
- height: 2px;
- background: linear-gradient(-45deg, rgba(0, 0, 255, 0), #5f91ff, rgba(0, 0, 255, 0));
- transform: translateX(50%) rotateZ(45deg);
- border-radius: 100%;
- -webkit-animation: shining 3000ms ease-in-out infinite;
- animation: shining 3000ms ease-in-out infinite;
- transform: translateX(50%) rotateZ(-45deg);
- }
- .shooting_star:nth-child(1) {
- top: calc(50% - 104px);
- left: calc(50% - 300px);
- -webkit-animation-delay: 4574ms;
- animation-delay: 4574ms;
- }
- .shooting_star:nth-child(1)::before, .shooting_star:nth-child(1)::after {
- -webkit-animation-delay: 4574ms;
- animation-delay: 4574ms;
- }
- .shooting_star:nth-child(2) {
- top: calc(50% - 153px);
- left: calc(50% - 183px);
- -webkit-animation-delay: 813ms;
- animation-delay: 813ms;
- }
- .shooting_star:nth-child(2)::before, .shooting_star:nth-child(2)::after {
- -webkit-animation-delay: 813ms;
- animation-delay: 813ms;
- }
- .shooting_star:nth-child(3) {
- top: calc(50% - -166px);
- left: calc(50% - 161px);
- -webkit-animation-delay: 9519ms;
- animation-delay: 9519ms;
- }
- .shooting_star:nth-child(3)::before, .shooting_star:nth-child(3)::after {
- -webkit-animation-delay: 9519ms;
- animation-delay: 9519ms;
- }
- .shooting_star:nth-child(4) {
- top: calc(50% - 176px);
- left: calc(50% - 163px);
- -webkit-animation-delay: 9645ms;
- animation-delay: 9645ms;
- }
- .shooting_star:nth-child(4)::before, .shooting_star:nth-child(4)::after {
- -webkit-animation-delay: 9645ms;
- animation-delay: 9645ms;
- }
- .shooting_star:nth-child(5) {
- top: calc(50% - 98px);
- left: calc(50% - 279px);
- -webkit-animation-delay: 6788ms;
- animation-delay: 6788ms;
- }
- .shooting_star:nth-child(5)::before, .shooting_star:nth-child(5)::after {
- -webkit-animation-delay: 6788ms;
- animation-delay: 6788ms;
- }
- .shooting_star:nth-child(6) {
- top: calc(50% - -46px);
- left: calc(50% - 235px);
- -webkit-animation-delay: 6197ms;
- animation-delay: 6197ms;
- }
- .shooting_star:nth-child(6)::before, .shooting_star:nth-child(6)::after {
- -webkit-animation-delay: 6197ms;
- animation-delay: 6197ms;
- }
- .shooting_star:nth-child(7) {
- top: calc(50% - -130px);
- left: calc(50% - 274px);
- -webkit-animation-delay: 6205ms;
- animation-delay: 6205ms;
- }
- .shooting_star:nth-child(7)::before, .shooting_star:nth-child(7)::after {
- -webkit-animation-delay: 6205ms;
- animation-delay: 6205ms;
- }
- .shooting_star:nth-child(8) {
- top: calc(50% - -143px);
- left: calc(50% - 173px);
- -webkit-animation-delay: 8236ms;
- animation-delay: 8236ms;
- }
- .shooting_star:nth-child(8)::before, .shooting_star:nth-child(8)::after {
- -webkit-animation-delay: 8236ms;
- animation-delay: 8236ms;
- }
- .shooting_star:nth-child(9) {
- top: calc(50% - 98px);
- left: calc(50% - 289px);
- -webkit-animation-delay: 3801ms;
- animation-delay: 3801ms;
- }
- .shooting_star:nth-child(9)::before, .shooting_star:nth-child(9)::after {
- -webkit-animation-delay: 3801ms;
- animation-delay: 3801ms;
- }
- .shooting_star:nth-child(10) {
- top: calc(50% - -35px);
- left: calc(50% - 177px);
- -webkit-animation-delay: 7845ms;
- animation-delay: 7845ms;
- }
- .shooting_star:nth-child(10)::before, .shooting_star:nth-child(10)::after {
- -webkit-animation-delay: 7845ms;
- animation-delay: 7845ms;
- }
- .shooting_star:nth-child(11) {
- top: calc(50% - -125px);
- left: calc(50% - 181px);
- -webkit-animation-delay: 8729ms;
- animation-delay: 8729ms;
- }
- .shooting_star:nth-child(11)::before, .shooting_star:nth-child(11)::after {
- -webkit-animation-delay: 8729ms;
- animation-delay: 8729ms;
- }
- .shooting_star:nth-child(12) {
- top: calc(50% - -35px);
- left: calc(50% - 97px);
- -webkit-animation-delay: 5926ms;
- animation-delay: 5926ms;
- }
- .shooting_star:nth-child(12)::before, .shooting_star:nth-child(12)::after {
- -webkit-animation-delay: 5926ms;
- animation-delay: 5926ms;
- }
- .shooting_star:nth-child(13) {
- top: calc(50% - -85px);
- left: calc(50% - 60px);
- -webkit-animation-delay: 1679ms;
- animation-delay: 1679ms;
- }
- .shooting_star:nth-child(13)::before, .shooting_star:nth-child(13)::after {
- -webkit-animation-delay: 1679ms;
- animation-delay: 1679ms;
- }
- .shooting_star:nth-child(14) {
- top: calc(50% - 186px);
- left: calc(50% - 70px);
- -webkit-animation-delay: 2818ms;
- animation-delay: 2818ms;
- }
- .shooting_star:nth-child(14)::before, .shooting_star:nth-child(14)::after {
- -webkit-animation-delay: 2818ms;
- animation-delay: 2818ms;
- }
- .shooting_star:nth-child(15) {
- top: calc(50% - -125px);
- left: calc(50% - 115px);
- -webkit-animation-delay: 6864ms;
- animation-delay: 6864ms;
- }
- .shooting_star:nth-child(15)::before, .shooting_star:nth-child(15)::after {
- -webkit-animation-delay: 6864ms;
- animation-delay: 6864ms;
- }
- .shooting_star:nth-child(16) {
- top: calc(50% - 73px);
- left: calc(50% - 9px);
- -webkit-animation-delay: 1772ms;
- animation-delay: 1772ms;
- }
- .shooting_star:nth-child(16)::before, .shooting_star:nth-child(16)::after {
- -webkit-animation-delay: 1772ms;
- animation-delay: 1772ms;
- }
- .shooting_star:nth-child(17) {
- top: calc(50% - -43px);
- left: calc(50% - 135px);
- -webkit-animation-delay: 2615ms;
- animation-delay: 2615ms;
- }
- .shooting_star:nth-child(17)::before, .shooting_star:nth-child(17)::after {
- -webkit-animation-delay: 2615ms;
- animation-delay: 2615ms;
- }
- .shooting_star:nth-child(18) {
- top: calc(50% - -92px);
- left: calc(50% - 2px);
- -webkit-animation-delay: 3037ms;
- animation-delay: 3037ms;
- }
- .shooting_star:nth-child(18)::before, .shooting_star:nth-child(18)::after {
- -webkit-animation-delay: 3037ms;
- animation-delay: 3037ms;
- }
- .shooting_star:nth-child(19) {
- top: calc(50% - -164px);
- left: calc(50% - 44px);
- -webkit-animation-delay: 6626ms;
- animation-delay: 6626ms;
- }
- .shooting_star:nth-child(19)::before, .shooting_star:nth-child(19)::after {
- -webkit-animation-delay: 6626ms;
- animation-delay: 6626ms;
- }
- .shooting_star:nth-child(20) {
- top: calc(50% - 14px);
- left: calc(50% - 256px);
- -webkit-animation-delay: 4858ms;
- animation-delay: 4858ms;
- }
- .shooting_star:nth-child(20)::before, .shooting_star:nth-child(20)::after {
- -webkit-animation-delay: 4858ms;
- animation-delay: 4858ms;
- }
- @-webkit-keyframes tail {
- 0% {
- width: 0;
- }
- 30% {
- width: 100px;
- }
- 100% {
- width: 0;
- }
- }
- @keyframes tail {
- 0% {
- width: 0;
- }
- 30% {
- width: 100px;
- }
- 100% {
- width: 0;
- }
- }
- @-webkit-keyframes shining {
- 0% {
- width: 0;
- }
- 50% {
- width: 30px;
- }
- 100% {
- width: 0;
- }
- }
- @keyframes shining {
- 0% {
- width: 0;
- }
- 50% {
- width: 30px;
- }
- 100% {
- width: 0;
- }
- }
- @-webkit-keyframes shooting {
- 0% {
- transform: translateX(0);
- }
- 100% {
- transform: translateX(300px);
- }
- }
- @keyframes shooting {
- 0% {
- transform: translateX(0);
- }
- 100% {
- transform: translateX(300px);
- }
- }
- @-webkit-keyframes sky {
- 0% {
- transform: rotate(45deg);
- }
- 100% {
- transform: rotate(405deg);
- }
- }
- @keyframes sky {
- 0% {
- transform: rotate(45deg);
- }
- 100% {
- transform: rotate(405deg);
- }
- }
- </style>
- </head>
- <body>
- <div class="night">
- <div class="shooting_star"></div>
- <div class="shooting_star"></div>
- <div class="shooting_star"></div>
- <div class="shooting_star"></div>
- <div class="shooting_star"></div>
- <div class="shooting_star"></div>
- <div class="shooting_star"></div>
- <div class="shooting_star"></div>
- <div class="shooting_star"></div>
- <div class="shooting_star"></div>
- <div class="shooting_star"></div>
- <div class="shooting_star"></div>
- <div class="shooting_star"></div>
- <div class="shooting_star"></div>
- <div class="shooting_star"></div>
- <div class="shooting_star"></div>
- <div class="shooting_star"></div>
- <div class="shooting_star"></div>
- <div class="shooting_star"></div>
- <div class="shooting_star"></div>
- </div>
- </body>
- </html>
复制代码
|
|