我在 2 div 之间有一个动画。理想情况下,我希望它们相互“插入”,这样感觉就像是一个在 Z 轴上旋转的 3d 盒子。
我有这个
body {
overflow:hidden
}
div {
position:absolute;
display:inline-block;
margin:0;
}
div:first-child {
left:0;
width:100%;
height:100%;
background-color:#453525;
transform:scaleX(1);
transition:transform .8s ease-out, width .8s ease-in, left .8s ease-in;
}
div:nth-child(2) {
left:101%;
width:0;
height:100%;
background-color:#754512;
transform:scaleX(0);
transition:transform .8s ease-out, width .8s ease-in, left .8s ease-in;
}
body:hover div:first-child {
transform:scaleX(0);
width:0;
left:-101%;
}
body:hover div:nth-child(2) {
transform:scaleX(1);
width:100%;
left:0;
}
<div>
</div>
<div>
</div>
如您所见,我的 div 之间有一个巨大的空间。我试图降低第一个 div 的过渡持续时间,以便第二个 div 接近,但无论如何我仍然得到一个空白。
有什么想法吗?
编辑:我元素中的 div 包含一些东西,所以当它放大或缩小时看起来像是在转动,这就是为什么我不单独使用简单的宽度或左过渡
最佳答案
我认为你可以摆脱左过渡并调整变换原点,以便两个 div 保持链接:
body {
overflow:hidden;
margin:0;
height:100vh;
}
div {
position:absolute;
display:inline-block;
margin:0;
}
div:first-child {
left:0;
width:100%;
height:100%;
background-color:#453525;
transform:scaleX(1);
transform-origin:right;
transition:transform .8s ease-out, width .8s ease-in;
}
div:nth-child(2) {
right:0;
width:0;
height:100%;
background-color:#754512;
transform:scaleX(0);
transform-origin:left;
transition:transform .8s ease-out, width .8s ease-in;
}
body:hover div:first-child {
transform:scaleX(0);
width:0;
}
body:hover div:nth-child(2) {
transform:scaleX(1);
width:100%;
}
<div>
</div>
<div>
</div>
关于html - css3 Transition 变换让元素之间的空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54113498/