【发布时间】:2016-11-27 04:28:01
【问题描述】:
我正在尝试仅在 CSS 中制作精美的动画。我从 W3 School 的教程开始,想把它做得更好。我的想法是让一个方形装载机顺时针转动,而另一个内部则向相反方向转动。
在this 链接上你会看到我在说什么,唯一的区别是我希望红色部分转向相反的方向。
为此,我尝试添加另一个类名为 .spinner 的 div。这是我的尝试:https://jsfiddle.net/avhjj4ps/
.loader-container {
position: absolute;
left: calc(50% - 75px);
width: 150px;
height: 150px;
padding: 5px;
border: 1px solid red;
top: calc(50% - 75px);
}
img {
width: 200px;
margin: 20px;
/*animation: move 2s alternate infinite linear;*/
}
#myClip, #svg {
position: absolute;
left: 50%;
top: 50%;
}
.loader, .spinner {
position: absolute;
}
.loader {
left: calc(50% - 35px);
top: calc(50% - 35px);
width: 40px;
height: 40px;
border: 15px solid transparent;
border-top: 15px solid none;
/*-webkit-animation: loader 2s linear infinite;
animation: loader 2s linear infinite;*/
}
.spinner {
left: calc(50% - 55.1px);
top: calc(50% - 55.1px);
/*clip-path: url(#myClip);*/
width: 40px;
border-radius: 50%;
height: 40px;
border: 36px solid #f3f3f3;
border-top: 36px solid #5cb85c;
/*-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;*/
}
@-webkit-keyframes loader {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
@keyframes loader {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
@-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(-360deg); }
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(-360deg); }
}
<div class="loader-container">
<div class="loader"></div>
<div class="spinner"></div>
<svg id="svg" width="0" height="0">
<defs>
<clipPath id="myClip">
<rect x="-35" y="-35" width="15" height="70" />
<rect x="20" y="-35" width="15" height="70" />
<rect x="-35" y="-35" width="70" height="15" />
<rect x="-35" y="20" width="70" height="15" />
</clipPath>
</defs>
</svg>
</div>
我试图仅在有方形装载机的地方显示绿色微调器。它就像一个面具。在上面的 sn-p 中(也可以在这里找到:http://codepen.io/anon/pen/ZOoByA),我正在尝试使用 clip-path 属性。
有人能告诉我为什么clip-path: url(#myClip); 不起作用吗?当我评论这一行时,加载程序完全显示,但是在活动时它根本不显示。
【问题讨论】:
标签: css css-animations clip-path