html - 在 CSS 中旋转地球

标签 html css css-animations

我正在 CSS 中创建一个旋转的地球效果。我用 CSS 创建了地球:

body {
  background-color: #111;
}

#earth {
    width: 300px;
    height: 300px;
    background: url(https://web.archive.org/web/20150807125159if_/http://www.noirextreme.com/digital/Earth-Color4096.jpg);
    border-radius: 50%;
    background-size: 610px;
    box-shadow: inset 8px 36px 80px 36px rgb(0, 0, 0),
    inset -6px 0 12px 4px rgba(255, 255, 255, 0.3);
    animation-name: rotate;
    animation-duration: 12s;
    animation-iteration-count: infinite;
    animation-timing-function: linear;
    -webkit-animation-name: rotate;
    -webkit-animation-duration: 12s;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-timing-function: linear;
}

@keyframes rotate {
    from { background-position: 0px 0px; }
    to { background-position: 500px 0px; }
}
@-webkit-keyframes rotate {
    from { background-position: 0px 0px; }
    to { background-position: 500px 0px; }
}
<div id="earth"></div>

但它停止了,然后图像重置并重新开始。我希望它平稳移动而不会抽搐。非常感谢!

最佳答案

background-position: 500px 0px;中将500px替换为610px,即background-size

body {
  background-color: #111;
}
#earth {
  width: 300px;
  height: 300px;
  background: url(https://web.archive.org/web/20150807125159if_/http://www.noirextreme.com/digital/Earth-Color4096.jpg);
  border-radius: 50%;
  background-size: 610px;
  box-shadow: inset 8px 36px 80px 36px rgb(0, 0, 0), inset -6px 0 12px 4px rgba(255, 255, 255, 0.3);
  animation-name: rotate;
  animation-duration: 12s;
  animation-iteration-count: infinite;
  animation-timing-function: linear;
  -webkit-animation-name: rotate;
     -webkit-animation-duration: 12s;
     -webkit-animation-iteration-count: infinite;
     -webkit-animation-timing-function: linear;
}
@keyframes rotate {
  from {
    background-position: 0px 0px;
  }
  to {
    background-position: 610px 0px;
  }
}
@-webkit-keyframes rotate {
  from {
    background-position: 0px 0px;
  }
  to {
    background-position: 610px 0px;
  }
}
<div id="earth"></div>

关于html - 在 CSS 中旋转地球,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36149947/

相关文章:

html - 搜索框不工作

css - 布局拼图 : align to Left AND Right plus a Centered box All connected with a Line

css - chrome 中的打印命令不应用 css 样式

部署后 CSS3 动画不工作

html - CSS3 动画 - 流畅的无限动画

html - 跨浏览器垂直居中文本

javascript - Android studio 从 sd 卡中的文件加载 javascript 函数

css - 如何让 3 个 div 显示在一行中,如果我调整浏览器大小则不会换行?

html - slideOut 侧边栏再次出现

html - 在没有重叠内容的情况下将 CSS @print 用于页眉/页脚