css - 是否可以使用转换 : scaleX() without affecting the border-radius?

标签 css css-animations css-transforms

我正在尝试生成一个简单的扩展条动画。除了受 scaleX() 转换影响的不断变化的 border-radius 外,一切正常,我可以根据自己的喜好控制它。有没有办法避免这种影响?

我假设为 border-radius 使用绝对单位就足够了,但事实并非如此。 scaleX() 仍然影响它。

重要提示:

我想使用 scaleX() 而不是使用 width 属性,因为我正在处理的元素具有各种变化的宽度,而我只想有一个动画与他们一起工作。

div {
  width: 200px;
  height: 20px;
  background-color: pink;
  border-radius: 10px;
  animation: expand;
  animation-duration: 10s;
  animation-iteration-count: infinite;
}

@keyframes expand {
  from {
    transform: scaleX(0.1);
  }
  to {
    transform: scaleX(1);
  }
}
<div />

最佳答案

I want to use scaleX() rather than working with the width property because the elements i am working on come with various changing widths and I want to have only one animation to work with them all.

不要指定 to,您的动画将适用于任何宽度:

.bar {
  width: 200px;
  height: 20px;
  background-color: pink;
  border-radius: 10px;
  animation: expand;
  animation-duration: 10s;
  animation-iteration-count: infinite;
}

@keyframes expand {
  from {
    width:20px;
  }
}
<div class="bar"></div>

<div class="bar" style="width:100px"></div>
<div class="bar" style="width:40px"></div>

关于css - 是否可以使用转换 : scaleX() without affecting the border-radius?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59772063/

相关文章:

javascript - jQuery 轮播幻灯片动画

javascript - Angular2 中的动态着色图形

jquery - 一个接一个地悬停时列表项的折叠效果

css - wow.js 仅在向下滚动一次时发生

css - 在 css 中创建摇摆/震动效果

html - 带边框和居中文本的透明梯形按钮

html - 如何使用 CSS 制作人字形箭头?

css - 为什么这个 CSS 动画在 IE10 中不起作用?

html - 当用户停止使用 CSS 将鼠标悬停在图像上时播放动画

javascript - 如何更新在我的 javascript 代码中单击的 div