如何固定画廊垂直中间的所有分辨率

HowI can fixed the gallery vertically middle for all resolution

本文关键字:分辨率 中间 垂直 何固定      更新时间:2023-09-26

最近我已经实现了画廊,客户说画廊应该垂直中间的所有分辨率,所以请建议我"我怎么能固定画廊垂直中间的所有分辨率。

您最好的选择是使用一些jQuery插件来居中的容器,需要在中间。是的,你可以用CSS来做,但那只有在元素是静态高度的时候。jQuery动态计算元素的高度,不需要静态的高度:)

我给你一个简单的居中插件链接:

Simple Vertical Align Plugin for jQuery

代码:

(function ($) {
// VERTICALLY ALIGN FUNCTION
$.fn.vAlign = function() {
    return this.each(function(i){
    var ah = $(this).height();
    var ph = $(this).parent().height();
    var mh = Math.ceil((ph-ah) / 2);
    $(this).css('margin-top', mh);
    });
};
})(jQuery);

如何调用:

$('#example p').vAlign();