【发布时间】:2015-06-19 05:14:19
【问题描述】:
如果有更好的方法来做我要问的问题,请告诉我,但到目前为止这是我能想到的最好的方法
我想要一组 div,其中包含一个滑动 div。滑动 div 将包含从最新帖子中提取的内容。所以它们可能并不总是完全相同的高度。
起始位置是显示标题,然后在父级悬停时显示整个 div。
我只使用底部位置时遇到的问题是,当屏幕变得太薄时,不仅会显示标题。使用top,我确实失去了一些头衔,但我愿意牺牲它。
因此,我决定同时使用顶部和底部,只需翻转 auto 所在的位置即可显示完整的 div。 (我不希望滑动 div 与包含 div 的高度相同)
但是,当我这样做时,过渡不起作用。我尝试在过渡中使用 top、bottom 和 all,但结果都是一样的 - 没有过渡。
有人可以解释一下 a) 为什么这不起作用 b) 如果不使用 jQuery,什么可以使它工作。
HTML:
<div class="innerLeftPosts">
<div class="mainPostHome">
<div class="postSlideCover">
<h3>Hello this is a test</h3>
<p>This is some test content that would go in here and take up some space</p>
</div>
</div>
<div class="secondaryPostHome">
<div class="postSlideCover">
<h3>Hello this is a test</h3>
<p>This is some test content that would go in here and take up some space</p>
</div>
</div>
</div>
CSS:
.postSlideCover{
width:calc(100% - 20px);
height:auto;
position:absolute;
transition:all 0.4s ease-out;
-webkit-transition:all 0.4s ease-out;
}
.mainPostHome .postSlideCover{
top:83%;
bottom:auto;
}
.mainPostHome:hover .postSlideCover{
top:auto;
bottom:0;
}
完整的视觉示例:https://jsfiddle.net/60nxpfs8/
【问题讨论】:
-
您无法转换到自动或从自动转换。
-
我假设是因为 css 不知道如何计算要移动多少?
-
如果是这样的话,我假设 jQuery 不仅更好,而且是唯一的选择。
-
Jquery 无法从
auto本地转换为 AFAIK,尽管已经为它编写了一些插件。但我看到你现在有了答案。 -
我会选择与自动驾驶不同的路线。可能是经过计算的。
标签: css