0

我正在开发一个 html5 应用程序,其中有一个固定的页眉和一个固定的页脚。

当我单击页脚时,它应该向上滑动,直到距离页眉 10 像素。

标题也应该发生同样的事情。

<div class="header"></div>
<div class="content"></div>
<div class="footer"></div>

默认布局的 CSS 很简单:我只使用顶部和底部的绝对定位。

.header, .footer {
    min-height:25px;
    background:grey;
    position:absolute;
    left:0;
    z-index:5;
    /** transition **/
    transition: all 1s;
}

.header {
    top:0;
    background:red;
}

.footer {
    bottom:0;
    background:yellow;
}
.header.max {
    bottom:35px;
}
.footer.max {
    top:35px;
}

不,它涉及动画部分。我不想使用 Javascript 动画!只有CSS! 如果您单击页眉或页脚,我只需将类添加max到元素中:

$(".header, .footer, .content").on("click", function () {
  $(".max").removeClass("max");
  $(this).addClass("max");
});

动画应该看起来像页脚从底部扩展。

我创建了一个JS-Fiddle。您可以看到,问题恰好出在页脚/页眉的顶部和底部位置。

有谁知道如何解决这个问题,使动画看起来像页脚从底部扩展?

谢谢!

4

1 回答 1

1

过渡元素需要设置为高度以获得更平滑的动画效果。在我的示例中,我将页眉和页脚动画设置为300px,您需要使用 JS 更改它以通过 window.height() 或类似的方式更新 class="max" 。

解决 10px 要求的一种方法是 onload get window.height() 减去 10px,然后用最终结果更新 class="max"。

我在您的 CSS 中所做的更改:

.header, .footer {
    min-height:25px;
    background:grey;
    position:absolute;
    left:0;
    z-index:5;
    /** transition **/
    transition:height 2s;
    -webkit-transition:height 2s; /* Safari */
}

.header.max {
   height:300px;
}
.footer.max {
   height:300px;
}

小提琴

http://jsfiddle.net/JSED5/3/

于 2013-11-15T19:27:27.260 回答