简体   繁体   English

摆脱关闭移动菜单 animation on window resize

[英]Getting rid of the closing mobile menu animation on window resize

I'm building a small website without JS for school and I'm stuck on an animation problem.我正在为学校建立一个没有 JS 的小型网站,但我遇到了 animation 问题。 I want to get rid of the closing animation on my mobile menu when resizing the window. Because currently, if I reduce the size of the window the menu will appear for a brief moment before going to the side (outside of the viewport).在调整 window 的大小时,我想摆脱移动菜单上的关闭 animation。因为目前,如果我减小 window 的大小,菜单会出现一小会儿,然后再转到侧面(视口之外)。

My menu general style in the media query is the following:我在媒体查询中的菜单一般样式如下:

        .menu {
            position: fixed;
            z-index: 80;
            width: 19rem;
            transform: translateX(100%);
            height: 100%;
            top: 0;
            right: 0;
            padding-top: 4.4rem;
            justify-content: revert;
            
            text-align: right;
            box-shadow: var(--b-shadow-l);
            background-color: seagreen;
            /* todo */
            transition: 800ms;
        }

When the menu is opened:打开菜单时:

            #mobile:checked ~ .menu {
                transform: translateX(0%);
                transition-property: transform;
                transition-duration: 800ms;
            }

Codepen to better see the situation: https://codepen.io/aayko/pen/OJEErBM Codepen更好看情况: https://codepen.io/aayko/pen/OJEErBM

My only solution so far is to remove the closing animation...到目前为止,我唯一的解决方案是删除结束 animation ...

I'm looking for anything, even if it means changing the way I style my mobile menu.我正在寻找任何东西,即使这意味着改变我设计移动菜单的方式。

Just remove the whole transform in your code above, instead give the right: -100% when normal and right: 0 when checked, the animation is the same without the flash disappear.只需删除上面代码中的整个transform ,而是给出right: -100%正常时和right: 0选中时,animation 相同,flash 消失。

.menu {
    position: fixed;
    z-index: 80;
    width: 19rem;
    height: 100%;
    top: 0;
    right: -100%;
    padding-top: 4.4rem;
    justify-content: revert;         
    text-align: right;
    box-shadow: var(--b-shadow-l);
    background-color: seagreen;
    /* todo */
    transition: 800ms;
}
#mobile:checked ~ .menu {
    right: 0;
}

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

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