修复了画布外不滚动的问题



我一直遇到一些我不明白的问题。我正在构建一个带有画布外下拉菜单的网站,该菜单拒绝滚动。我已经添加了overflow-y: scroll,并在其他一些网站上使用了几乎相同的东西,在那里它就像一个魅力。但是一旦我用我的Android打开这个网站,如果它溢出,我就无法滚动菜单。我面临着移动火狐,chrome和opera的问题,所有最新版本。

现场演示

完整的代码可以在这里看到:https://github.com/bekreatief/bekreatief.github.io/tree/master/demo/off-canvas

菜单标记:

<section class="main_menu">
    <nav id="menu">
        <a href="#" class="toggle_link"><i class="fa fa-close fa-lg"></i></a>
        <ul>
            <li>
                <a href="#">Item</a>
            </li>
            <li>
                <a href="#">Item</a>
            </li>
            <li>
                <a href="#">Item</a>
            </li>
            <li class="menu-item-has-children">
                <a href="#">Parent</a>
                <ul>
                    <li>
                        <a href="#">subitem</a>
                    </li>
                    <li>
                        <a href="#">subitem</a>
                    </li>
                </ul>
            </li>
            <li>
                <a href="#">Item</a>
            </li>
            <li class="menu-item-has-children">
                <a href="#">Parent</a>
                <ul>
                    <li>
                        <a href="#">subitem</a>
                    </li>
                    <li>
                        <a href="#">subitem</a>
                    </li>
                    <li>
                        <a href="#">subitem</a>
                    </li>
                </ul>
            </li>
            <li>
                <a href="#">Item</a>
            </li>
        </ul>
    </nav>
</section>

菜单萨斯

// Main Nav
.main_menu{
    background: $mainnav_bg;
    text-align: center;
    position: relative;
    top: 0px;
    width: 100%;
    left: 0px;
    border-top: $border;
    border-bottom: $border;
    text-transform: uppercase;
}
#menu{
    position: relative;
    margin: 0px auto;
    display: block;
    background: $mainnav_bg;
    max-width: $max-width;
    box-sizing: border-box;
    color: $mainnav_a_color;
    font-size: 1em;
    width: 100%;
    z-index: 105;
    a{
        color: $mainnav_a_color;
        &:hover{
            color: $mainnav_a_hover;
        }
    }
    .toggle_link{
        display: none;
    }
    > ul {
        text-align: center;
    }
    li{
        display: inline-block;
        padding: 20px 7px;
        transition: .3s all linear;
        > a{
            width: 100%;
            display: block;
        }
        &:hover{
            transition: .3s all linear;
            > a{
                color: $mainnav_a_hover;
            }
        }
    }
    // Drop Down
    .menu-item-has-children{
        margin-left: 0;
        position: relative;
        > a{
            &:before{
                content:"+ ";
            }        
        }
        > ul{
            padding-top: 0px;
            display: none;
            max-height: 100%;
            overflow-y: auto;
            @media screen and (min-width: $mainnav_collapse+1){
                background: $mainnav_bg;
                position: absolute;
                top: 100%;
                left: 50%;
                transform: translateX(-50%);
                width: auto;
                border-top: $border;
                border-left: $border;
                border-right: $border;
                &:before{
                    content: "";
                    width: 10px;
                    height: 10px;
                    background: $mainnav_bg;
                    position: absolute;
                    top: -6px;
                    left: 50%;
                    transform: translateX(-50%) rotate(45deg);
                    border-left: $border;
                    border-top: $border;
                }
            }
            li{
                display: block;
                padding: 10px 0px;
                @media screen and (min-width: $mainnav_collapse+1){
                    padding: 10px 30px;
                    border-bottom: $border;
                }
            }
        }
        &:hover,
        &:focus{
            cursor: pointer;
            > ul{
                display: block;
            }
        }
    }
    .open{
        > ul{
            display: block;
        }            
    }
    // Responsive Version (Off-Canvas)
    @media screen and (max-width: $mainnav_collapse){
        padding: 35px 0px 0px;
        width: 320px;
        height: 80vh;
        position: fixed;
        top: 0px;
        right: -320px;
        transform: translate(10px, 10px);
        transition: .3s all ease;
        z-index: 108;
        box-shadow: 0px 0px 5px 0px rgba(black, .5);
        overflow-y: scroll !important;
        &.active{
            transform: translate(-340px, 20px);
            transition: .3s all ease;
        }
        .toggle_link{
            display: block;
            position: absolute;
            top: 5px;
            right: 5px;
            &:after{
                content: "";
            }
        }
        > ul{
            text-align: $mainnav_responsive_text_align;
            width: 100%;
            position: relative;
            max-height: 100%;
            overflow-y: scroll !important;
        }
        li{
            display: block;
            padding: 10px 15px;
            border-top: 1px solid lighten($mainnav_bg, 5%);
            &:first-of-type{
                border-top: $noborder;
            }
            &:hover{
                transition: .3s all linear;
                background: rgba($mainnav_a_hover_bg, .4);
            }
        }
        // Sub Items
        .menu-item-has-children{
            margin-left: 0;
            > ul{
                padding-top: 15px;
                display: none;
                li{
                    padding: 10px 0px;
                    &:first-of-type{
                        border-top: 1px solid lighten($mainnav_bg, 5%);
                    }
                }
            }
            &:hover,
            &:focus{
                cursor: pointer;
                > ul{
                    display: block;
                }
            }
        }
        .open{
            > ul{
                display: block;
            }            
        }
    }
}
// Toggle
.toggle_link{
    @media screen and (min-width: $mainnav_collapse){
        display: none;
    }
}

和 js

$(document).ready(function () {
    // Responsive Menu
    $(".toggle_link").click(function () {
        $("#menu").toggleClass("active");
    });
    $(".menu-item-has-children a").attr("aria-haspopup", "true");
    $(".menu-item-has-children a").click(function () {
        $(this).parent().toggleClass("open");
    });
});

我发现了问题。它是由skrollr引起的,我打算在页面的另一部分使用它。但是由于我还在开发中,我删除了 skrollr,它现在正在按预期工作。

相关内容

  • 没有找到相关文章

最新更新