【发布时间】:2019-07-24 22:51:24
【问题描述】:
单击按钮时,我有 flex-box 动画,但是当它发生时,img 会稍微晃动(来回 1-2px 之类的),它非常轻微但很明显,如果你很难看到这个让我知道我会尝试制作视频。
代码笔:https://codepen.io/MariusZMM/pen/PLzodX
html,
body {
width: 100%;
height: 100%;
background: #544;
}
.container {
position: relative;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
height: 100%;
}
.item {
height: 100%;
position: relative;
overflow: hidden;
}
.item .cA,
.item .lI {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
.f1 {
-webkit-box-flex: 0;
-ms-flex-positive: 0;
flex-grow: 0;
}
.f2 {
-webkit-box-flex: 1;
-ms-flex-positive: 1;
flex-grow: 1;
}
.f2 .btn {
position: absolute;
width: 50%;
height: 70px;
top: 80%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background: #444;
}
.img {
background-image: url("https://davidcrew.files.wordpress.com/2010/01/wallpaper-177057.jpg");
background-attachment: fixed;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
height: 100%;
}
.f3 {
-webkit-box-flex: 1.5;
-ms-flex-positive: 1.5;
flex-grow: 1.5;
}
<div class="container">
<div class="item f1" style="background: red"></div>
<div class="item f2 img">
<button class="btn">
<div class="sI">Sign In</div>
</button>
</div>
<div class="item f3" style="background: blue"></div>
</div>
【问题讨论】:
-
我认为问题出在背景位置:已修复;此属性在 Google chrome 中存在性能问题。
-
你可能是对的,但我在 Safari 上尝试过同样的问题。 Firefox 没有这个问题。
-
Chrome 我指的是 Web-kit 浏览器。这可能会有所帮助:fourkitchens.com/blog/article/… Removing background-position: fixed;将解决滚动问题
-
是的,我正在阅读类似的内容medium.com/vehikl-news/… 将尝试回复结果
标签: html css flexbox css-transforms