简体   繁体   中英

Make the Drawer open when switching to small screen

I trying to use Material Design Lite and made a small interface. And now I face with a problem - I need to make the Drawer always open, when window loads and when window goes from large screen to small. By default, the Drawer always starts with close state...

I found that some changes comes, when I hit Drawer button (pink color on screenshot).

I tried to use QuerySelector like that:

var obfuscator = document.querySelector('.mdl-layout__obfuscator');
obfuscator.className = 'mdl-layout__obfuscator is-visible'

but it cant detect that element... Can someone gimme better way to do such simple task?)) I really stacked with it...

在此处输入图片说明

Based on link, that Cody gave in the comment, I got that.

    window.onload = function() {
        var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0)
        if (w <= 1000) {
            document.querySelector('.mdl-layout__obfuscator').classList.add('is-visible');
            document.querySelector('.mdl-layout__drawer').classList.add('is-visible');
        };
    };

So now Drawer start opened when screen size below or equal 1000px. My first mistake was that I missed that material.js loads up with defer and because of that I cant find mdl-layout__obfuscator and mdl-layout__drawer . Like always, stupid mistakes made pain in... u know that place :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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