css – 如何让Material-UI Drawer在打开时“挤压”其他内容

前端之家收集整理的这篇文章主要介绍了css – 如何让Material-UI Drawer在打开时“挤压”其他内容前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如果有人熟悉css和Material UI,那么对此的任何帮助将非常感激.
基本上我正在尝试实现一个Material UI Drawer组件,它在打开时不会滑过页面内容的顶部,而是页面内容符合抽屉,即挤压或扩展.我在我的项目中使用bootstrap行和容器,但我不知道如何使用它们来实现这一点.这是我的组件的布局方式:
<div>
    <AppBar
    onLeftIconButtonTouchTap={this.handleToggle}
      title="Imaginary Company"
    />
    <Row>
      <QuotesList />
    </Row>
    <Drawer
    containerStyle={{ top: 64,width:150 }}
    open={this.state.open}
    >
      <MenuItem>Menu Item</MenuItem>
      <MenuItem>Menu Item 2</MenuItem>
    </Drawer>
  </div>

注意’top’属性只是因为我希望应用栏的顶部标题区域在抽屉打开或关闭时保持可见.
一如既往,任何帮助都会令人惊叹!干杯

更新:我找到了一种适合我的hacky解决方案.使用令人敬畏的’样式组件’库(允许样式根据您传入的动态道具进行更改)我能够创建一个包装器组件,它接受’折叠’道具,向右滑动的动画等于抽屉的宽度(150).如果有人偶然发现这个并且他们感兴趣的是我在样式组件中的代码(那里也有一些复制和粘贴的bootstrap容器样式):

const CollapsibleContainer = styled.div`
margin-left: auto;
margin-right: auto;
padding-left: 15px;
padding-right: 15px;
$:after {
content: "";
display: table;
clear: both;
}
position: absolute;
right: 0;
left: ${props => props.collapsed ? '150px' : '0'}!important;
transition: 450ms cubic-bezier(0.23,1,0.32,1) 0ms;
`;

也许这不是完美的解决方案,但它看起来很好.希望这有助于某人:)

解决方法

类似于你的“hacky”解决方案,但这里是一个jsFiddle: https://jsfiddle.net/88uq8751/3/

同样的主流.你向右移动你的内容与抽屉的宽度相同的距离,并使用相同的过渡/动画…这可以通过使用某种形式或组合宽度,marginLeft,绝对位置甚至变换的各种方式来完成:翻译,但我在下面使用了marginLeft:

const { Drawer,RaisedButton,MuiThemeProvider,getMuiTheme } = MaterialUI;

class Example extends React.Component {
  constructor(props) {
    super(props);
    this.state = { drawerOpen: false };
  }

  render() {
    const contentStyle = {  transition: 'margin-left 450ms cubic-bezier(0.23,1)' };

    if (this.state.drawerOpen) {
      contentStyle.marginLeft = 256;
    }

    return (
      <div>
        <Drawer open={this.state.drawerOpen}>
          <div style={{ textAlign: 'right' }}>
            <RaisedButton onClick={() => this.setState({ drawerOpen: false }) }>X</RaisedButton>
          </div>
          {this.props.children}
        </Drawer>
        <div style={contentStyle}>
          <RaisedButton onClick={() => this.setState({ drawerOpen: true }) }>Open</RaisedButton>
          <p>
            Lorem ipsum dolor sit amet,amet epicuri vel ea,noster cauSAE oporteat has ut,ad est periculis concludaturque.Mundi docendi volutpat ut sea,an sea suas epicurei.Sea numquam definitionem ne.Te postea aliquip invidunt quo.Id prima commune complectitur pri,sed at vero posse contentiones,sea cu fugit etiam iusto.Ei mei prima appareat,est brute luptatum iudicabit id.Alii homero imperdiet usu id,dico meis alienum per ad,dolorem mentitum philosophia quo id.
          </p><p>
            Nec in dolor ancillae contentiones,at harum graecis his.An delectus scripserit pro.Ei dicta liber vis,sed no quidam legimus fabellas,no expetendis vituperata mei.Vim et ferri nominavi constituto.Wisi tamquam intellegebat duo in.Omittam adolescens abhorreant no sea.Cibo iusto verear ut mea,per at viris nominavi referrentur.
          </p><p>
            Sea officiis moderatius te.Graeci cauSAE malorum ius in,cu has offendit tractatos interpretaris.Ea porro liberavisse mei,no mei propriae salutandi intellegat,te nibh singulis vim.Vim mucius feugait blandit ea.At est mollis vivendo.Eu has choro doctus verterem.Utroque suscipiantur ne eum,vix in alia intellegat.
          </p><p>
            Lorem ipsum dolor sit amet,vix in alia intellegat.
          </p>        
        </div>
    </div>
    );
  }

}

const App = () => (
  <MuiThemeProvider muiTheme={getMuiTheme() }>
    <Example />
  </MuiThemeProvider>
);

ReactDOM.render(
  <App />,document.getElementById('container')
);
原文链接:https://www.f2er.com/css/217919.html

猜你在找的CSS相关文章