如何实现最大高度和使用YUI面板的滚动条?

时间:2011-06-24 17:00:53

标签: javascript yui

我正在使用通过AJAX调用呈现的YUI Panel元素。有没有办法设置最大高度,并在面板内容超过该高度时使用滚动条?

2 个答案:

答案 0 :(得分:1)

当然!以下是带有id dlg:

的Dialog的示例
var dialog = new YAHOO.widget.Dialog("dlg", { fixedcenter : true....

然后将bd css类设置为auto overflow:

#dlg .bd {
    overflow: auto;
}

然后在你的js中输入类似的内容:

YAHOO.util.Dom.setStyle(dialog.body, "height", "300px");

你可能还需要在ft类中添加一些样式,但这取决于你:

#dlg .ft {
    padding-top: 10px;
    border-top: 1px solid #CECECE;
}

答案 1 :(得分:0)

如果您不在乎特定的高度,而只是想避免它大于窗口,那么下面的代码将对此进行处理。

myDialog.renderEvent.subscribe(function() {
    // Find .yui-panel .bd
    let dialogElement = $('.yui-panel .bd');
    // set the max-height to the 90% of the screen
    let windowHeight = $(window).height();
    dialogElement.css('max-height', windowHeight*0.9);
    // set overflow:auto
    dialogElement.css('overflow', 'auto');
});
相关问题