我刚刚继承了一些代码,部分代码显示浮动div并居中。用jQuery居中浮动div
下面是代码:
function showFloatingDialog(element) {
removeMessage();
var height, width;
var offsetY = $(document).scrollTop();
if (offsetY == undefined) {
offsetY = 0;
}
var dialog = $('#' + element);
dialog.show();
height = (($(window).width() - dialog.width())/2);
width = ($(window).height() - dialog.height())/2;
width = width + offsetY;
height = height - 195;
width = width - 130;
dialog.css('position', 'absolute');
dialog.css('left', height + 'px');
dialog.css('top', width + 'px');
}
在它的防御,它完美的作品,但我下面的线条看起来像一个黑客:
width = width + offsetY;
height = height - 195;
width = width - 130;
有没有得到更好的和更合适的方法与此相同的结果。
这是一个坚实而干净的方法。此外,它不经意地解决了垂直对齐/显示:表格单元故障。 –