首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >谁能告诉我为什么在CSS的cubic-bezier函数中position:fixed是必需的?

谁能告诉我为什么在CSS的cubic-bezier函数中position:fixed是必需的?
EN

Stack Overflow用户
提问于 2019-01-10 11:18:04
回答 2查看 77关注 0票数 0

这是下面的代码,它有位置:fixed。如果我删除这一行,那么我的立方函数就不能简单地工作了。谁能告诉我这样的定位是如何工作的?此外,建议一些资源,以更好地理解定位。

代码语言:javascript
复制
<style>

  .balls{
    border-radius: 50%;
    background: linear-gradient(
      35deg,
      #ccffff,
      #ffcccc
    );
    position: fixed;  
    width: 50px;
    height: 50px;
    margin-top: 50px;
    animation-name: bounce;
    animation-duration: 2s;
    animation-iteration-count: infinite;
  }
  #ball1 { 
    left: 27%;
    animation-timing-function: linear;
  }
  #ball2 { 
    left: 56%;
    animation-timing-function: ease-out;
  }

@keyframes bounce {
  0% {
    top: 0px;
  } 
  100% {
    top: 249px;
  }
} 

</style>
代码语言:javascript
复制
<div class="balls" id= "red"></div>
<div class="balls" id= "blue"></div>

EN

回答 2

Stack Overflow用户

发布于 2019-01-10 13:51:09

用这个替换你的CSS,

代码语言:javascript
复制
.balls{
    border-radius: 50%;
    background: linear-gradient(
      35deg,
      #ccffff,
      #ffcccc
    );
    width: 50px;
    height: 50px;
    animation-name: bounce;
    animation-duration: 2s;
    animation-iteration-count: infinite;
  }
  #red { 
    position: absolute;
    left: 200px;
    animation-timing-function: linear;
  }
  #blue { 
    position: absolute;
    left: 500px;
    animation-timing-function: ease-out;
  }
@keyframes bounce {
  0%{
    top:0;
  }
  100%{
    top:200px;
  }
} 

为了让元素移动,您需要使用CSS

  • 属性,它可以是相对的,也可以不是必需的,因为它会将元素固定在screen.So上,当您向下滚动时,对象将沿屏幕移动。

如果你想学习定位,你可以查看这个:https://developer.mozilla.org/en-US/docs/Web/CSS/position

票数 0
EN

Stack Overflow用户

发布于 2019-01-10 14:18:05

动画会更改要设置动画的元素的topleft属性。

只有当元素的位置设置为fixedabsoluterelative时,这些属性才会生效。

删除行position: fixed会将元素的位置设置为position: static,从而导致topleft属性无效。

有关定位的一些资源,请查看https://www.w3schools.com/css/css_positioning.asp

它解释了可以应用于元素的定位属性,以及topbottomrightleft属性在每种情况下的作用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54121500

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档