简体   繁体   English

在MDL中打开抽屉时调整内容大小

[英]Resize content when drawer is open in MDL

I'm building a website based on MDL. 我正在建立一个基于MDL的网站。 What I'm trying to achieve is that the drawer doesn't open over the content, but open next to it. 我要实现的目标是,抽屉不在内容上打开,而是在内容旁边打开。 I managed to disable the obfuscator and modify the top value. 我设法禁用混淆器并修改了top价值。

However, the way I was going to do this is anytime the drawer opens the content area would get a 250px wide left margin (the drawer is 250px wide) and resize its width so that width: calc(100% - 250px) . 但是,我要这样做的方法是在抽屉打开内容区域的任何时候都将获得250px宽的左侧边距(抽屉为250px宽),并调整其宽度大小以使width: calc(100% - 250px) This works just fine, but I don't know if this is the best way to do it, and even if it is, I don't know how to track the state of the drawer. 这很好用,但是我不知道这是否是最好的方法,即使是这样,我也不知道如何跟踪抽屉的状态。

Here's how the material.js handles the change: 这是material.js处理更改的方式:

MaterialLayout.prototype.screenSizeHandler_ = function () {
    if (this.screenSizeMediaQuery_.matches) {
        this.element_.classList.add(this.CssClasses_.IS_SMALL_SCREEN);
    } else {
        this.element_.classList.remove(this.CssClasses_.IS_SMALL_SCREEN);
        // Collapse drawer (if any) when moving to a large screen size.
        if (this.drawer_) {
            this.drawer_.classList.remove(this.CssClasses_.IS_DRAWER_OPEN);
            this.obfuscator_.classList.remove(this.CssClasses_.IS_DRAWER_OPEN);
        }
    }
};

This is beyond my skills to figure out what is actually going on. 这超出了我的能力,无法弄清实际情况。 I tried tracking it down with Chrome, but it was too complicated. 我尝试使用Chrome浏览器进行跟踪,但这太复杂了。

Is there a trivial way to do this? 有没有简单的方法可以做到这一点? If not, how do I edit the script? 如果没有,如何编辑脚本?

Cheers! 干杯!

The .mdl-layout__drawer receives a .is-visible class when it is open/visible. .mdl-layout__drawer在打开/可见时会收到一个.mdl-layout__drawer .is-visible类。 This small CSS-Rule worked for me: 这个小的CSS-Rule为我工作:

.mdl-layout__drawer.is-visible ~ .mdl-layout__content {
    padding-left: 250px;
}

With this you also don't need to fix the width of the content-area, as you are not using margin but padding. 使用此功能,您也不需要固定内容区域的宽度,因为您不使用边距而是使用填充。 Note that by default the material.css also disables scrolling when the drawer is visible, so you also need to add the overflow-property to the rule: 请注意,默认情况下,material.css还会在可见抽屉时禁用滚动,因此您还需要向规则添加溢出属性:

.mdl-layout__drawer.is-visible ~ .mdl-layout__content {
    overflow: auto !important;
    padding-left: 250px;
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM