简体   繁体   English

初始化为可见时,如何使AlloyUI模态主体正确呈现:false?

[英]How to get AlloyUI modal body to render properly when initialized as visible: false?

I'm using the AlloyUI modal "Real World Example" directly from their website at: http://alloyui.com/examples/modal/real-world/ 我直接从他们的网站(网址为http://alloyui.com/examples/modal/real-world/)使用AlloyUI模态“真实世界示例”

Using the example verbatim and changing the following line from: 使用逐字显示示例,并将以下行更改为:

   visible: true,

to

   visible: false,

So that the modal appears only after clicking the button instead of when the page loads, as one would expect a dialog box to do. 这样模态仅在单击按钮后才出现,而不是在页面加载时出现,就像人们期望对话框那样。 When I click the button to "show modal" the modal loads however the body of the dialog doesn't fill it's space properly, and the toolbar is mashed up against it. 当我单击按钮以“显示模态”时,模态加载,但是对话框的主体无法正确填充其空间,工具栏也紧贴在它上面。 Upon resize everything jumps back into place nicely. 调整大小后,所有内容都会很好地跳回原位。

I'm looking for a clean fix, so far I figure a hacky fix might be to load the modal with a zIndex that puts it behind the page body, and alter the z-index via CSS with the button click (but this seems really hackish). 我正在寻找一个干净的修复程序,到目前为止,我认为一个有问题的修复程序可能是使用zIndex加载模式并将其放在页面主体后面,然后通过单击按钮通过CSS更改z-index(但这似乎确实是的hackish)。 I could probably also programatically resize the modal after the button fires modal.show() but that would cause a visible jump in the layout which I would like to avoid. 在按钮触发modal.show()之后,我也可能会以编程方式调整模式的大小,但这会导致布局出现可见的跳跃,我想避免这种跳跃。

Any suggestions? 有什么建议么? I know AlloyUI has tons of hidden goodies, as their documentation is sparse, perhaps the visible attribute is not the one I should be using? 我知道AlloyUI有很多隐藏的东西,因为它们的文档稀疏,也许可见属性不是我应该使用的属性?

After some research I found an answer to my own question, this still may be a hacky fix but until someone comes up with something better here is the solution. 经过研究,我找到了自己的问题的答案,这可能仍然是个错误的解决方案,但是直到有人提出更好的解决方案为止。

 Step 1: 
 Leave visible: true intact.

 Step 2: 
 Invoke .hide() after setting up the modal

The complete code. 完整的代码。

YUI().use('aui-modal', function(Y) {
    var modal = new Y.Modal({
        bodyContent: '<div id="dialogBody"><div id="myTab"></div></div>',
        centered: true,
        headerContent: '<h3>Modal Goodness</h3>',
        height: 600,
        modal: true,
        render: '#modal',
        width: 900
    }).render();

    modal.addToolbar([
        {
          label: 'Save',
          on: {
            click: function() {
              alert('You clicked save!');
            }
          }
        },
        {
          label: 'Close',
          on: {
            click: function() {
              modal.hide();
            }
          }
        }
    ]);

    modal.hide();

    Y.one('#showModal').on(
        'click',
        function() {
            modal.show();
        }
    );
});

I've done it nearly as you, just a little difference 我几乎和你一样做了,只是有一点点不同

                  modal = new Y.Modal(
                  {
                    centered: true,
                    contentBox: '#contentBox',
                    destroyOnHide: false,
                    headerContent: '<h3>Informations to your Orders</h3>',
                    height: 400,
                    modal: true,
                    render: '#modal',
                    resizable: {
                      handles: 'b, r'
                    },
                    visible: true,
                    width: 450
                  }
                ).hide();

I replaced .render() with hide(), by clicking a button this lines of codes are called: 通过单击按钮,我用hide()替换了.render(),这行代码称为:

                Y.all('#showModal').on(
                  'click',
                  function() {
                    modal.show();
                  }
                );

Can't find a method or parameter on YUI API Docs to stop auto render, so that seems to be the 'usual' way. YUI API文档上找不到方法或参数来停止自动渲染,因此这似乎是“通常”的方式。 I thought it might be the attribute render , but setting it to false or deleting the attribute don't make any changes to the auto init behaviour. 我认为这可能是属性render ,但是将其设置为false或删除属性不会对自动初始化行为做出任何更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过Javascript动态渲染AlloyUI模态正文HTML - Dynamically Rendering AlloyUI Modal body HTML via Javascript AlloyUI模态重用模态 - AlloyUI modal reuse modal 如何修复AlloyUI模式总是出现在图表画布下面? - How to fix AlloyUI modal always showing up below diagram canvas? 如何在 redux 调度完成时正确获取,然后渲染组件 - How to properly get when the redux dispatch is done, to then render a Component 在AngularJS中切换视图时如何使MathML正确呈现 - How to get MathML to render properly when switching views in AngularJS 在 b-modal 中使用 b-overlay 时,模态主体不可见 - When using b-overlay in b-modal the modal body is not visible 打开模式/灯箱时如何滚动锁定主体 - How to scrollLock body when a modal/lightbox is open 修复了SubSonic 2.2日历,当控件不可见时,如何获取RegisterClientScriptInclude调用以进行渲染? - Fixing the SubSonic 2.2 Calendar, How do I get RegisterClientScriptInclude calls to render when control is not visible? Phaser是否渲染可见设置为false的精灵? - Does Phaser render sprites with visible set to false? 当可见更改为false时,为什么JQuery无法获取Textarea值? - Why JQuery is unable to get Textarea value when the visible changed to false?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM