[英]vertical align div within a div using jquery?
任何人有jquery vAligh插件或类似的经验?
我尝试调整以下但是它失败了..我使用的是一个简单的valign插件(我将插件放在最后,它是一个jquery扩展),如果有人可以帮助它会真的很有帮助...
var overlayLayer = $("<div id='office-location'></div>").addClass('modal-overlay');
$('body').append(overlayLayer);
$('<div id="content-for-overlay" style="background-color: white;"></div>').appendTo(overlayLayer);
this.render({ to: "content-for-overlay", partial: "office-location-modal" }); // this just copies html into the layer
$('#content-for-overlay').vAlign(); THIS USES a plugin called valign but it doesn't align
$("body").css("overflow", "hidden");
$('#office-location').css("opacity", 0.8).fadeIn(150);
$('#content-for-overlay').css("opacity", 1);
继承人FN扩展..
(function($) {
$.fn.vAlign = function() {
return this.each(function(i) {
var h = $(this).height();
var oh = $(this).outerHeight();
var mt = (h + (oh - h)) / 2;
$(this).css("margin-top", "-" + mt + "px");
$(this).css("top", "50%");
$(this).css("position", "absolute");
});
};
})(jQuery的);
你可以尝试使用一个CSS技术中心垂直项目,如图所示这里 。 我相信这种方法是跨浏览器的,但不幸的是它为你的标记添加了额外的div。
使用jQuery,使用$().css()
将此css应用于标记相当容易$().css()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.