css - 容器的变换比例和子容器的逆变换比例

标签 css transform scale transition easing

我在 CSS 中遇到缩放问题。 div.containertransform: scale(0.1),所以因为正常的字体大小,这个元素的h1transform: scale (10)

悬停后,div.containertransform: scale(0.5)h1 transform: scale(2)。一切都是动画的(transition: all 1s ease-in-out)。

但是,h1 的动画速度不如 div.container 的动画快,所以在 hover 之后,h1 非常大动画开始,然后快速收缩。

我认为这是因为 h1 应该有反转缓动。但是什么缓动与 ease-in-out 相反?还是其他地方的问题?

注意:我不能只缩放 div.image。此代码只是示例。我必须缩放 div.container

.container, .title {
  transition: all 1s ease-in-out;
}

.image {
  background-image: url(https://www.w3schools.com/css/trolltunga.jpg);
  background-size: 100% auto;
  background-repeat: no-repeat;
  height: 300px;
  width: 800px;
}

.container {
  transform: scale(0.1);
}

.title {
  margin: 0;
  text-align: center;
  padding-top: 1rem;
  transform: scale(10);
}

.container:hover {
  transform: scale(0.5);
}

.container:hover .title {
  transform: scale(2);
}
<div class="container">
   <div class="image">
   
   </div>
   <h1 class="title">Title</h1>
</div>

最佳答案

我发现它不适用于线性缓动。所以,问题不在于放松。

.container, .title {
  transition: all 1s linear;
}

.image {
  background-image: url(https://www.w3schools.com/css/trolltunga.jpg);
  background-size: 100% auto;
  background-repeat: no-repeat;
  height: 300px;
  width: 800px;
}

.container {
  transform: scale(0.1);
}

.title {
  margin: 0;
  text-align: center;
  padding-top: 1rem;
  transform: scale(10);
}

.container:hover {
  transform: scale(0.5);
}

.container:hover .title {
  transform: scale(2);
}
<div class="container">
   <div class="image">
   
   </div>
   <h1 class="title">Title</h1>
</div>

关于css - 容器的变换比例和子容器的逆变换比例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44831225/

相关文章:

html - 如何解决此 HTML 间距问题?

javascript - 单击按钮时不会显示音频控件 JavaScript

支持 Pinch-Zoom 和 Scrolling 的 Android ImageViewer 类

asp.net - 替换 web.config 转换中的 IIS 重写规则

java - 如何在 geotools 中创建一个简单的 map 比例尺

cocoa - 在 Cocoa 中缩放 WebView

javascript - 如何在 iOS UIWebView 中缩放 iFrame

html - 实现单选输入的 CSS 默认浏览器

html - 蒙版 svg 元素不显示整个 svg 元素

iphone - 限制在 IOS 中使用捏合手势缩放图像的最大比例