【发布时间】:2017-01-24 21:29:53
【问题描述】:
我正在通过background-image 属性显示微调器。
正如您在示例中看到的,微调器并未从其中心旋转。
我尝试使用 transform-origin 属性,但它不起作用。
body {
background: #5daf47;
}
.spinner {
height: 150px;
width: 150px;
transform-origin: center center;
background-size: 150px;
background-image: url('https://dl.dropboxusercontent.com/u/3057457/spinner.svg');
}
<div class="spinner"></div>
这是我的 svg 的内容:
<svg x="0px" y="0px" viewBox="0 0 150 150" xmlns="http://www.w3.org/2000/svg">
<style>
svg {
width: 150px;
animation: loading 3s linear infinite;
}
circle {
animation: loading-circle 2s linear infinite;
stroke: white;
fill: transparent;
-webkit-transform-origin: center center;
-moz-transform-origin: center center;
-ms-transform-origin: center center;
-o-transform-origin: center center;
transform-origin: center center;
}
@keyframes loading {
0% {
transform: rotate(0);
}
100% {
transform: rotate(360deg);
}
}
@keyframes loading-circle {
0% {
stroke-dashoffset: 0
}
100% {
stroke-dashoffset: -600;
}
}
</style>
<circle cx="75" cy="75" r="60" stroke-width="4" stroke-dashoffset="0" stroke-dasharray="300" stroke-miterlimit="10" stroke-linecap="round"></circle>
</svg>
如何让这个微调器从中心旋转?
感谢您的帮助。
【问题讨论】:
-
您使用的是 Firefox 吗?但它适用于 Chrome/IE 吗?
-
@Robbie 我只在 Chrome 中测试它。没试过 Firefox/IE。
-
好的 - 问的原因是有一个 Firefox 错误,即使设置了转换原点,如果它不是直接在父级上,Firefox 将围绕 0,0 而不是原点旋转。但因为它不是 Firefox,所以让我看起来...
-
我认为您可能需要重新考虑它。它在 Firefox 中显示一个绿色框,因此 50% 的观众将看不到任何内容