[英]Css3 Animation with rotate
I am using a background to rotate globe. 我正在使用背景旋转地球仪。 But it stop/jerk after some rotation.
但是经过一些旋转后它会停止/跳动。 I am not sure where i am making mistake and why its jerking after some rotations.
我不确定我在哪里犯错,以及为什么在轮流旋转后会出现抽搐。
Here is the code with fiddle 这是带有小提琴的代码
HTML HTML
<div id="earth">
</div>
CSS CSS
body {
background-color: black;
}
#earth {
width: 143px;
height: 143px;
background: url(http://www.noirextreme.com/digital/Earth-Color4096.jpg);border-radius: 50%;
background-size: 320px;
box-shadow: inset 1px 0 27px 1px rgb(5, 5, 5), inset -3px 0 5px 2px rgba(255, 255, 255, 0.2);
-webkit-animation-name: rotate;
-webkit-animation-duration: 4s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-name: rotate;
-moz-animation-duration: 4s;
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: linear;
-ms-animation-name: rotate;
-ms-animation-duration: 4s;
-ms-animation-iteration-count: infinite;
-ms-animation-timing-function: linear;
animation-name: rotate;
animation-duration: 4s;
animation-iteration-count: infinite;
animation-timing-function: linear;
z-index: 9999;
position: relative;
margin-left: 52px;
}
@-webkit-keyframes rotate {
from { background-position-x: 0px; }
to { background-position-x: 210px; }
}
@-ms-keyframes rotate {
from { background-position-x: 0px; }
to { background-position-x: 210px; }
}
@-moz-keyframes rotate {
from { background-position-x: 0px; }
to { background-position-x: 210px; }
}
@keyframes rotate {
from { background-position-x: 0px; }
to { background-position-x: 210px; }
}
Fiddle: http://jsfiddle.net/k54QN/ 小提琴: http : //jsfiddle.net/k54QN/
您的“到” background-position
应等于图像的宽度。
Add this to #earth 将此添加到#earth
transform: translate3d(0,0,0);
-webkit-transform: translate3d(0,0,0);
It'll use the the GPU for hardware acceleration. 它将使用GPU进行硬件加速。
@-webkit-keyframes rotate {
from { background-position-x: 0px; }
to { background-position-x: 590px; }
}
@-ms-keyframes rotate {
from { background-position-x: 0px; }
to { background-position-x: 590px; }
}
@-moz-keyframes rotate {
from { background-position-x: 0px; }
to { background-position-x: 590px; }
}
@keyframes rotate {
from { background-position-x: 0px; }
to { background-position-x: 590px; }
}
Try changing the background-position-x from "TO", one thing that might be a problem is that it'll rotate faster, but then you just extend the animation time. 尝试将background-position-x从“ TO”更改为,可能会出现的问题是,它旋转得更快,但是您只是延长了动画时间。
Edited for 43px globe: 针对43px地球编辑:
Match background-size
like this: 像这样匹配
background-size
:
#earth {
width: 43px;
height: 43px;
background-size: 86px, 43px; //Height should match height of globe (unless you don't want to see the poles) and width should be 2x height
@-webkit-keyframes rotate {
from { background-position: 0px 0px; }
to { background-position: 86px 0px; } //Match Width
}
@-ms-keyframes rotate {
from { background-position: 0px 0px; }
to { background-position: 86px 0px; } //Match Width
}
@-moz-keyframes rotate {
from { background-position: 0px 0px; }
to { background-position: 86px 0px; } //Match Width
}
@keyframes rotate {
from { background-position: 0px 0px; }
to { background-position: 86px 0px; } //Match Width
}
Working fiddle: 工作提琴:
Change the background-position to the width of the image, and don't use background-position-x. 将background-position更改为图像的宽度,并且不要使用background-position-x。 It's not supported in most browsers.
大多数浏览器均不支持该功能。
body {
background-color: black;
}
#earth {
width: 243px;
height: 243px;
background: url(http://www.noirextreme.com/digital/Earth-Color4096.jpg);border-radius: 50%;
background-size: 620px;
box-shadow: inset 1px 0 27px 1px rgb(5, 5, 5), inset -3px 0 5px 2px rgba(255, 255, 255, 0.2);
-webkit-animation-name: rotate;
-webkit-animation-duration: 4s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-name: rotate;
-moz-animation-duration: 4s;
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: linear;
-ms-animation-name: rotate;
-ms-animation-duration: 4s;
-ms-animation-iteration-count: infinite;
-ms-animation-timing-function: linear;
animation-name: rotate;
animation-duration: 4s;
animation-iteration-count: infinite;
animation-timing-function: linear;
z-index: 9999;
position: relative;
margin-left: 52px;
}
@-webkit-keyframes rotate {
from { background-position: 0px 0px; }
to { background-position: 620px 0px; }
}
@-ms-keyframes rotate {
from { background-position: 0px 0px; }
to { background-position: 620px 0px; }
}
@-moz-keyframes rotate {
from { background-position: 0px 0px; }
to { background-position: 620px 0px; }
}
@keyframes rotate {
from { background-position: 0px 0px; }
to { background-position: 620px 0px; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.