html - 如何动画扩展/收缩而不是向上/向下

标签 html css css-animations

我试图让这条线表现得像一缕阳光,沿对 Angular 线向右下方 (↘) 和向左上方 (↖) 移动。尽管使用了高度降低,但我得到的是上/下。

在 GIF 中预览(使用图像编辑器创建):

animation preview

body {
    background-color: grey;
}

.sunray {
    height: 200px; 
    width: 5px;
    background-color: white;
    opacity: 0.9; 
    filter: blur(5px);  
    transform: rotate(135deg); 
    position: relative;
    left: 60px;
    top: -50px;
} 
   
.sunray {
    animation: ray 1s linear infinite;
    animation-direction: alternate-reverse;
}
   
@keyframes ray {
    from { height: 200px; }
    to   { height: 50px; }
}
<div class="sunray"></div>

最佳答案

body {
  background-color: grey;
}

.container {
  height: 200px;
  width: 200px;
  overflow: hidden;
  outline: 1px solid black;
}

.sunray {
  height: 200px;
  width: 5px;
  background-color: white;
  opacity: 0.9;
  filter: blur(5px);
  position: relative;
  left: 60px;
  top: -50px;
}

.sunray {
  animation: ray 1s linear infinite;
  animation-direction: alternate-reverse;
}

@keyframes ray {
  from {
    transform: translate(-50px, -50px) rotate(-45deg);
  }
  to {
    transform: rotate(-45deg);
  }
}
<div class="container">
  <div class="sunray"></div>
</div>

关于html - 如何动画扩展/收缩而不是向上/向下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59594931/

相关文章:

android - 移动图像上传先处理?

html - CSS 动画 : drop in from top of fold

python - 从 HTML 文档中提取 CSS 和 HTML 注释 (Python)

javascript - 如何使用 Javascript 打印到 HTML 标签

javascript - 将 div 移出屏幕的最佳方式?

html - 如何使用 z-index 以正确的顺序显示标签

CSS 延续浏览器属性

html - 背景位置动画运行不流畅

php - 使用 domDocument 和 DOMXPath 解析 HTML

jquery - CSS 垂直 JQuery 菜单