gpt4 book ai didi

jquery - 从中心扩大div

转载 作者:行者123 更新时间:2023-11-28 07:17:01 26 4
gpt4 key购买 nike

我有一个带有放大/缩小背景图像的 div。它位于基于滚动改变高度的导航中。我正在使用效果很好的 css 过渡,但是随着行高、填充等的变化,我希望它从图像的中心开始缩放。

CSS

header {
position: fixed;
overflow: hidden;
z-index: 100;
height: 125px;
background-color: rgba(250,250,250,1);
width: 100%;
top: 0; left: 0;
padding: 0 25px;
-webkit-transition: height 0.35s ease;
-moz-transition: height 0.35s ease;
-ms-transition: height 0.35s ease;
-o-transition: height 0.35s ease;
transition: height 0.35s ease;
}
.brand {
display: inline-block;
height: 100px;
width: 100px;
margin: 10px 0;
background: url('img/logo.png') no-repeat center center;
background-size: contain;
-webkit-transition: height 0.35s ease, width 0.35s ease;
-moz-transition: height 0.35s ease, width 0.35s ease;
-ms-transition: height 0.35s ease, width 0.35s ease;
-o-transition: height 0.35s ease, width 0.35s ease;
transition: height 0.35s ease, width 0.35s ease;
}

导航较小时的 CSS

header.shrink {
height: 80px;
line-height: 80px;
}

header.shrink .brand {
height: 40px;
width: 40px;
margin: 20px 0;
}

最佳答案

Updated Fiddle

解释

CSS 边距和过渡可用于实现从中心(相对于先前大小的 x 方向和相对于父元素、标题的 y 方向)的动画收缩。此处发布的解决方案对宽度、高度和边距 使用已知值,以确保在大和小之间切换时图像保持居中。

动画看起来是从中心开始的,因为边距、宽度和高度正在以相同的速率同时动画化。 Image Demonstration

CSS:

header, .brand {
/* Animate for 0.35s */
-webkit-transition: all 0.35s ease;
-moz-transition: all 0.35s ease;
-ms-transition: all 0.35s ease;
-o-transition: all 0.35s ease;
transition: all 0.35s ease;
}

/* Enlarged styles */
header {
width: 100%;
height: 125px;
position: fixed;
overflow: hidden;
z-index: 100;
background-color: black;
top: 0; left: 0;
padding: 0 25px;
}
.brand {
width: 100px;
height: 100px;
margin: 10px 0;
display: inline-block;
background: url('http://img1.wikia.nocookie.net/__cb20120104232844/steamplane/images/b/b0/Happy_Face_100x100.gif') no-repeat center center;
background-size: contain;
}

/* Small styles */
header.shrink {
height: 80px;
line-height: 80px;
}
header.shrink .brand {
width: 40px;
height: 40px;

/* Margin shorthand translates to:
* - Top, bottom margins: 20px each
* - Left, right margins: 30px each
*/
margin: 20px 30px;
}

/* Button */
#button{
margin-top: 130px;
cursor: pointer;
}

关于jquery - 从中心扩大div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32295847/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com