• <tfoot id='O484O'></tfoot>
    • <bdo id='O484O'></bdo><ul id='O484O'></ul>

    <small id='O484O'></small><noframes id='O484O'>

    <i id='O484O'><tr id='O484O'><dt id='O484O'><q id='O484O'><span id='O484O'><b id='O484O'><form id='O484O'><ins id='O484O'></ins><ul id='O484O'></ul><sub id='O484O'></sub></form><legend id='O484O'></legend><bdo id='O484O'><pre id='O484O'><center id='O484O'></center></pre></bdo></b><th id='O484O'></th></span></q></dt></tr></i><div id='O484O'><tfoot id='O484O'></tfoot><dl id='O484O'><fieldset id='O484O'></fieldset></dl></div>

        <legend id='O484O'><style id='O484O'><dir id='O484O'><q id='O484O'></q></dir></style></legend>
      1. 如何创建带有转换的 React 模态(附加到`&lt;body&gt;`)?

        时间:2023-06-13

        <i id='xTLri'><tr id='xTLri'><dt id='xTLri'><q id='xTLri'><span id='xTLri'><b id='xTLri'><form id='xTLri'><ins id='xTLri'></ins><ul id='xTLri'></ul><sub id='xTLri'></sub></form><legend id='xTLri'></legend><bdo id='xTLri'><pre id='xTLri'><center id='xTLri'></center></pre></bdo></b><th id='xTLri'></th></span></q></dt></tr></i><div id='xTLri'><tfoot id='xTLri'></tfoot><dl id='xTLri'><fieldset id='xTLri'></fieldset></dl></div>
        <tfoot id='xTLri'></tfoot>

          <bdo id='xTLri'></bdo><ul id='xTLri'></ul>

          1. <legend id='xTLri'><style id='xTLri'><dir id='xTLri'><q id='xTLri'></q></dir></style></legend>
            • <small id='xTLri'></small><noframes id='xTLri'>

                <tbody id='xTLri'></tbody>

                • 本文介绍了如何创建带有转换的 React 模态(附加到`&lt;body&gt;`)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这个答案中有一个模式 https://stackoverflow.com/a/26789089/883571 正在创建通过将其附加到 <body> 的基于 React 的 Modal.但是,我发现它与 React 提供的过渡插件不兼容.

                  There is a modal in this answer https://stackoverflow.com/a/26789089/883571 which is creating a React-based Modal by appending it to <body>. However, I found it not compatible with the transition addons provided by React.

                  如何创建一个带过渡的(进入和离开时)?

                  How to create one with transitions(during enter and leave)?

                  推荐答案

                  在 react conf 2015 上,Ryan Florence 展示了使用门户.以下是创建简单 Portal 组件的方法...

                  At react conf 2015, Ryan Florence demonstrated using portals. Here's how you can create a simple Portal component...

                  var Portal = React.createClass({
                    render: () => null,
                    portalElement: null,
                    componentDidMount() {
                      var p = this.props.portalId && document.getElementById(this.props.portalId);
                      if (!p) {
                        var p = document.createElement('div');
                        p.id = this.props.portalId;
                        document.body.appendChild(p);
                      }
                      this.portalElement = p;
                      this.componentDidUpdate();
                    },
                    componentWillUnmount() {
                      document.body.removeChild(this.portalElement);
                    },
                    componentDidUpdate() {
                      React.render(<div {...this.props}>{this.props.children}</div>, this.portalElement);
                    }
                  });
                  

                  然后,您通常可以在 React 中执行的所有操作都可以在门户内部执行...

                  and then everything you can normally do in React you can do inside of the portal...

                      <Portal className="DialogGroup">
                         <ReactCSSTransitionGroup transitionName="Dialog-anim">
                           { activeDialog === 1 && 
                              <div key="0" className="Dialog">
                                This is an animated dialog
                              </div> }
                         </ReactCSSTransitionGroup>
                      </Portal> 
                  

                  jsbin 演示

                  你也可以看看 Ryan 的 react-modal,虽然我实际上没有使用它,所以我不知道它与动画效果如何.

                  jsbin demo

                  You can also have a look at Ryan's react-modal, although I haven't actually used it so I don't know how well it works with animation.

                  这篇关于如何创建带有转换的 React 模态(附加到`&lt;body&gt;`)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何知道模态框(警报、提示、确认...)是否已在 javascript 中被禁用? 下一篇:使用 :before CSS 伪元素将图像添加到模态

                  相关文章

                    <bdo id='fR7ps'></bdo><ul id='fR7ps'></ul>
                • <tfoot id='fR7ps'></tfoot>
                  1. <i id='fR7ps'><tr id='fR7ps'><dt id='fR7ps'><q id='fR7ps'><span id='fR7ps'><b id='fR7ps'><form id='fR7ps'><ins id='fR7ps'></ins><ul id='fR7ps'></ul><sub id='fR7ps'></sub></form><legend id='fR7ps'></legend><bdo id='fR7ps'><pre id='fR7ps'><center id='fR7ps'></center></pre></bdo></b><th id='fR7ps'></th></span></q></dt></tr></i><div id='fR7ps'><tfoot id='fR7ps'></tfoot><dl id='fR7ps'><fieldset id='fR7ps'></fieldset></dl></div>

                  2. <small id='fR7ps'></small><noframes id='fR7ps'>

                    <legend id='fR7ps'><style id='fR7ps'><dir id='fR7ps'><q id='fR7ps'></q></dir></style></legend>