简体   繁体   English

将子div设置为父div的中心

[英]animating child div to the center of parent div

I have a 2*2 matrix where the child div should zoom in and the remaining div's should be hidden. 我有一个2 * 2矩阵,子div应该放大,其余的div应该隐藏。

I made this animation where every thing is working fine except that the div should like it is coming from its position but with my implementation every thing seems to come from the top left corner. 我制作了这个动画 ,其中所有东西都可以正常工作,但div应该像它来自其位置一样,但是在我的实现中,所有东西似乎都来自左上角。

example : when user clicks on the div two it should seem like it should come from right top corner but now it is coming from left top corner. 示例:当用户单击div 2时,似乎应该来自右上角,但是现在它来自左上角。

any suggestions to make this work 任何使这项工作的建议

FIDDLE 小提琴

Use absolute positioning. 使用绝对定位。 You can either declare the CSS beforehand or inject it with JS. 您可以预先声明CSS或将其注入JS。

.one, .two, .three, .four {
    position: absolute;
}
.two, .four {
    right: 0 !important;
}
.one, .two {
    top: 0;
}
.three, .four {
    top: 100px;
}
.big {
    top: 10% !important;
}

See Updated Fiddle 参见更新的小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM