英文:
<v-navigation-drawer> has come to the side of the footer
问题
我想动态设置我给一个元素设置的样式的高度值。具体来说,当滚动到底部时,高度为77.5%,当页脚元素完全不可见时,高度为100%,当页脚可见时,我想从100%中减去高度。
我尝试了各种方法,但在handleScroll中无法很好地调整高度。请让我知道是否有一种方法可以调整。
.v-navigation-drawer {
height: 77.5% !important;
}
当我将页脚放在v-main中时,它变成了如下所示。
<v-main>
<v-container>
<slot></slot>
<NavigationLink />
<v-footer
border="t"
style="position: absolute; left: 0; right: 0; z-index: 9999"
>
<v-row justify="center" no-gutters>
<AppThemeToggle />
<v-col
class="primary lighten-2 py-4 text-center white--text"
cols="12"
>
<strong>
Copyright {{ new Date().getFullYear() }} vuetify Corporation
</strong>
</v-col>
</v-row>
</v-footer>
</v-container>
</v-main>
如果导航内容覆盖了页脚,我想像下面的图片一样滚动它。
英文:
I would like to dynamically set the height value of a style that I set to an element. Specifically, when scrolling to the bottom, the height of the height is 77.5%, when the footer element is not visible at all, it is 100%, and when the footer is visible, it is the visible value I want to subtract the height from 100%.
I tried various things with handleScroll below, but I can't adjust the height well. Please let me know if there is a way to adjust
.v-navigation-drawer {
height: 77.5% !important;
}
Below is the full code.
<template>
<v-app>
<Header />
<!-- <TableofContents /> -->
<v-navigation-drawer width="300" border="r" app> test </v-navigation-drawer>
<v-main>
<v-container>
<slot />
</v-container>
<NavigationLink />
</v-main>
<v-footer border="t">
<v-row justify="center" no-gutters>
<AppThemeToggle />
<v-col class="primary lighten-2 py-4 text-center white--text" cols="12">
<strong
>Copyright {{ new Date().getFullYear() }} vuetify
Corporation</strong
>
</v-col>
</v-row>
</v-footer>
</v-app>
</template>
When I put the footer in v-main, it became as follows.
<v-main>
<v-container>
<slot />
<NavigationLink />
<v-footer
border="t"
style="position: absolute; left: 0; right: 0; z-index: 9999"
>
<v-row justify="center" no-gutters>
<AppThemeToggle />
<v-col
class="primary lighten-2 py-4 text-center white--text"
cols="12"
>
<strong
>Copyright {{ new Date().getFullYear() }} vuetify
Corporation</strong
>
</v-col>
</v-row>
</v-footer>
</v-container>
</v-main>
If the content of the navigation covers the footer, I would like to scroll it like the image below
答案1
得分: 2
如果我理解正确,您希望将导航栏放在页眉和页脚之间:
------------ ------------
| header | | header |
------------ ------------
| n | | | n | |
| a | main | 而不是 | a | main |
| v | | | v | |
------------ | |-------
| footer | | | foot |
------------ ------------
布局组件,如 VAppBar、VNavigationDrawer 或带有 :app
属性的 VFooter,根据它们声明的顺序来占用空间,除了 VMain,它总是占用剩余的空间。所以在上面的示例中,左边的顺序是 header-footer-nav,而右边的顺序是 header-nav-footer(与您的示例相同)。
所以,不要手动调整高度,只需更改元素的顺序:
<template>
<v-app>
<v-app-bar />
<v-footer app> ... </v-footer>
<v-navigation-drawer> ... </v-navigation-drawer>
<v-main> ... </v-main>
</v-app>
</template>
如果您希望页脚与主内容一起滚动,您不能使用 app 页脚,因为它固定在页面上。我认为还没有一种优雅的解决方案可以将页脚放在导航栏上方,但您可以将页脚放入 v-main
中并对其设置绝对位置:
<v-app>
<v-app-bar>...</v-app-bar>
<v-navigation-drawer>...</v-navigation-drawer>
<v-main>
...
<v-footer style="position: absolute; left: 0; right: 0; z-index: 9999;">...</v-footer>
</v-main>
</v-app>
查看 playground。
英文:
If I understand correctly, you want the navbar between header and footer:
------------ ------------
| header | | header |
------------ ------------
| n | | | n | |
| a | main | instead of | a | main |
| v | | | v | |
------------ | |-------
| footer | | | foot |
------------ ------------
Layout components like VAppBar, VNavigationDrawer or VFooter (with :app
prop) work by claiming space in order they are declared, except for VMain, which will always claim the leftover space. So in above example, the left one has order header-footer-nav, while the right one has order header-nav-footer (same as your example).
So instead of manually adjusting height, just change the order of the elements:
<template>
<v-app>
<v-app-bar />
<v-footer app> ... </v-footer>
<v-navigation-drawer> ... </v-navigation-drawer>
<v-main> ... </v-main>
</v-app>
</template>
<!-- begin snippet: js hide: true console: false babel: false -->
<!-- language: lang-js -->
Vue.createApp({}).use(Vuetify.createVuetify()).mount('#app')
<!-- language: lang-html -->
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/vuetify@3/dist/vuetify.min.css" />
<link href="https://cdn.jsdelivr.net/npm/@mdi/font@5.x/css/materialdesignicons.min.css" rel="stylesheet">
<div id="app">
<v-app>
<v-app-bar>header</v-app-bar>
<v-footer app border="t"> footer </v-footer>
<v-navigation-drawer border="r" permanent>drawer</v-navigation-drawer>
<v-main class="bg-grey"> Main content </v-main>
</v-app>
</div>
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@3/dist/vuetify.min.js"></script>
<!-- end snippet -->
If you want the footer to scroll with the main content, you cannot use the app footer, as it is fixed on the page. I don't think there is an elegant solution to get the footer inside main yet over the nav bar. But you can put the footer into v-main
and set absolute position on it:
<v-app>
<v-app-bar>...</v-app-bar>
<v-navigation-drawer>...</v-navigation-drawer>
<v-main>
...
<v-footer style="position: absolute; left: 0; right: 0; z-index: 9999;"
>...</v-footer>
</v-main>
</v-app>
see playground
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论