定位超大的jQuery.UI对话框

时间:2012-01-29 18:46:09

标签: jquery jquery-ui jquery-dialog

我的仪表板屏幕上有三列排列的对话框。它运作得很好。

var leftContent;
var middleContent;
var rightContent;
var verticalOffset;

$(document).ready(function() {
    leftContent = $('#columnTop');
    middleContent = $('#columnTop');
    rightContent = $('#columnTop');
    verticalOffset = (jQuery.browser.safari) ? 40 : 5;

    includeJavascriptFile('inlineForumFunctions.js');

    $('.dialog').each(function(){
        var p = '';
        if ($(this).hasClass('dialogLeft')) p = 'posLeft';
        if ($(this).hasClass('dialogCenter')) p = 'posCenter';
        if ($(this).hasClass('dialogRight')) p = 'posRight';

        $(this).dialog({
            title: $(this).attr('title'),
            maxHeight: 400
        }).parent().attr('id', $(this).attr('id') + 'Dialog')
        .addClass('cfDialog').addClass(p);
    });

    $('.cfDialog').css('width', '30%');

    $('.cfDialog.posLeft').each(function(){
        addToLeftColumn($(this).attr('id'));
    });

    $('.cfDialog.posCenter').each(function(){
        addToCenterColumn($(this).attr('id'));
    });

    $('.cfDialog.posRight').each(function(){
        addToRightColumn($(this).attr('id'));
    });

    $('.menu ul').hover(function(){
        $(this).maxZIndex();
        $(this).children().maxZIndex();
    });

});

$.maxZIndex = $.fn.maxZIndex = function(opt) {
    /// <summary>
    /// Returns the max zOrder in the document (no parameter)
    /// Sets max zOrder by passing a non-zero number
    /// which gets added to the highest zOrder.
    /// </summary>
    /// <param name="opt" type="object">
    /// inc: increment value,
    /// group: selector for zIndex elements to find max for
    /// </param>
    /// <returns type="jQuery" />
    var def = {
        inc: 10,
        group: "*"
    };
    $.extend(def, opt);
    var zmax = 0;
    $(def.group).each(function() {
        var cur = parseInt($(this).css('z-index'));
        zmax = cur > zmax ? cur : zmax;
    });
    if (!this.jquery)
        return zmax;

    return this.each(function() {
        zmax += def.inc;
        $(this).css("z-index", zmax);
    });
}

function addToLeftColumn(elementId){
        $('#'+elementId)
        .position({
            my: 'left top',
            at: 'left bottom',
            of: leftContent,
            offset: '0 ' + verticalOffset
        });
    if ($('#'+elementId).html().length > 0){
        leftContent = $('#'+elementId);
    }
}

function addToCenterColumn (elementId){
        $('#'+elementId)
        .position({
            my: 'center top',
            at: 'center bottom',
            of: middleContent,
            offset: '0 ' + verticalOffset
        });
        alert(middleContent.attr('id'));
        middleContent = $('#'+elementId);

}

function addToRightColumn (elementId){
        $('#'+elementId)
        .position({
            my: 'right top',
            at: 'right bottom',
            of: rightContent,
            offset: '0 ' + verticalOffset
        });
    if ($('#'+elementId).html().length > 0){
        rightContent = $('#'+elementId);
    }
}

...但是,maxHeight属性似乎被忽略了。我有一个大于400像素的对话框,当屏幕呈现时,屏幕顶部会显示对话框的最底边。

为什么会这样?

1 个答案:

答案 0 :(得分:1)

您想要设置height属性,否则为automaxHeight属性用于可由用户调整大小的对话框。