gpt4 book ai didi

javascript - 具有透明背景的 CSS 馅饼微调器/加载器

转载 作者:行者123 更新时间:2023-11-28 02:43:49 25 4
gpt4 key购买 nike

我只需要使用 css 和 javascript 制作一个饼图旋转器/加载器。

到目前为止,我设法让它在背景为纯色时工作,因为它不需要查看隐藏半圆的 div(不要介意颜色和顶部/左侧):

.wrapper {
position: relative;
background: transparent;
width: 50px;
height: 50px;
background: gray;
}

.wrapper,
.wrapper * {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}

.wrapper .pie,
.wrapper * .pie {
width: 50%;
height: 100%;
transform-origin: 100% 50%;
position: absolute;
background: red;
}

.wrapper .spinner,
.wrapper * .spinner {
border-radius: 100% 0 0 100%/50% 0 0 50%;
z-index: 200;
border-right: none;
animation: rota 5s linear infinite
}

.wrapper .filler,
.wrapper * .filler {
border-radius: 0 100% 100% 0/0 50% 50% 0;
left: 50%;
opacity: 0;
z-index: 100;
border-left: none;
background: red;
animation: opa 5s steps(1, end) infinite reverse
}

.wrapper .mask,
.wrapper * .mask {
width: 50%;
height: 100%;
position: absolute;
background: inherit;
opacity: 1;
z-index: 300;
animation: opa 5s steps(1, end) infinite
}

.wrapper:hover .spinner,
.wrapper:hover .filler,
.wrapper:hover .mask {
animation-play-state: running;
}

@-moz-keyframes rota {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

@-webkit-keyframes rota {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

@-o-keyframes rota {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

@keyframes rota {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

@-moz-keyframes opa {
0% {
opacity: 1;
}
50%,
100% {
opacity: 0;
}
}

@-webkit-keyframes opa {
0% {
opacity: 1;
}
50%,
100% {
opacity: 0;
}
}

@-o-keyframes opa {
0% {
opacity: 1;
}
50%,
100% {
opacity: 0;
}
}

@keyframes opa {
0% {
opacity: 1;
}
50%,
100% {
opacity: 0;
}
}
<div class="wrapper">
<div class="pie spinner"></div>
<div class="pie filler"></div>
<div class="mask"></div>
</div>

问题是,我需要使背景透明,这样我才能看到它,但是 mask div 变得无用了:

body {
background-image: url(http://www.publicdomainpictures.net/pictures/20000/velka/tulip-flower-garden.jpg)
}

.wrapper {
position: relative;
background: transparent;
width: 50px;
height: 50px;
background: transparent;
}

.wrapper,
.wrapper * {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}

.wrapper .pie,
.wrapper * .pie {
width: 50%;
height: 100%;
transform-origin: 100% 50%;
position: absolute;
background: red;
}

.wrapper .spinner,
.wrapper * .spinner {
border-radius: 100% 0 0 100%/50% 0 0 50%;
z-index: 200;
border-right: none;
animation: rota 5s linear infinite
}

.wrapper .filler,
.wrapper * .filler {
border-radius: 0 100% 100% 0/0 50% 50% 0;
left: 50%;
opacity: 0;
z-index: 100;
border-left: none;
background: red;
animation: opa 5s steps(1, end) infinite reverse
}

.wrapper .mask,
.wrapper * .mask {
width: 50%;
height: 100%;
position: absolute;
background: inherit;
opacity: 1;
z-index: 300;
animation: opa 5s steps(1, end) infinite
}

.wrapper:hover .spinner,
.wrapper:hover .filler,
.wrapper:hover .mask {
animation-play-state: running;
}

@-moz-keyframes rota {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

@-webkit-keyframes rota {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

@-o-keyframes rota {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

@keyframes rota {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

@-moz-keyframes opa {
0% {
opacity: 1;
}
50%,
100% {
opacity: 0;
}
}

@-webkit-keyframes opa {
0% {
opacity: 1;
}
50%,
100% {
opacity: 0;
}
}

@-o-keyframes opa {
0% {
opacity: 1;
}
50%,
100% {
opacity: 0;
}
}

@keyframes opa {
0% {
opacity: 1;
}
50%,
100% {
opacity: 0;
}
}
<div class="wrapper">
<div class="pie spinner"></div>
<div class="pie filler"></div>
<div class="mask"></div>
</div>

有没有可能实现我想要的?怎么办?

最佳答案

.wrapper {
position: relative;
background: transparent !important;
width: 50px;
height: 50px;
background: gray;
}

.wrapper,
.wrapper * {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}

.wrapper .pie,
.wrapper * .pie {
width: 50%;
height: 100%;
transform-origin: 100% 50%;
position: absolute;
background: red;
}

.wrapper .spinner,
.wrapper * .spinner {
border-radius: 100% 0 0 100%/50% 0 0 50%;
z-index: 200;
border-right: none;
animation: rota 5s linear infinite
}

.wrapper .filler,
.wrapper * .filler {
border-radius: 0 100% 100% 0/0 50% 50% 0;
left: 50%;
opacity: 0;
z-index: 100;
border-left: none;
background: red;
animation: opa 5s steps(1, end) infinite reverse
}

.wrapper .mask,
.wrapper * .mask {
width: 50%;
height: 100%;
position: absolute;
background: inherit;
opacity: 1;
z-index: 300;
animation: opa 5s steps(1, end) infinite
}

.wrapper:hover .spinner,
.wrapper:hover .filler,
.wrapper:hover .mask {
animation-play-state: running;
}

@-moz-keyframes rota {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

@-webkit-keyframes rota {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

@-o-keyframes rota {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

@keyframes rota {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

@-moz-keyframes opa {
0% {
opacity: 1;
}
50%,
100% {
opacity: 0;
}
}

@-webkit-keyframes opa {
0% {
opacity: 1;
}
50%,
100% {
opacity: 0;
}
}

@-o-keyframes opa {
0% {
opacity: 1;
}
50%,
100% {
opacity: 0;
}
}

@keyframes opa {
0% {
opacity: 1;
}
50%,
100% {
opacity: 0;
}
}
<div class="wrapper">
<div class="pie spinner"></div>
<div class="pie filler"></div>
<div class="mask"></div>
</div>

添加背景透明重要

.wrapper { background: transparent !important; }

关于javascript - 具有透明背景的 CSS 馅饼微调器/加载器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42416277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com