简体   繁体   English

具有固定边栏布局的NuxtJs nuxt-link滚动行为

[英]NuxtJs nuxt-link scroll behaviour with fixed sidebar layout

I'm currently building a Nuxt application with a layout of a fixed sidebar on the left side of the page, and scrollable content on the right side of the page. 我目前正在构建Nuxt应用程序,该应用程序在页面的左侧固定有侧边栏的布局,在页面的右侧具有可滚动的内容。

Because of this layout I use flexbox with overflow:hidden on the page wrapping div, and on the content container overflow:scroll 由于这种布局,我在包装div的内容容器上和内容容器上的overflow:scroll上使用了具有boxbox的flexbox:

You can view the code for this here: https://jsfiddle.net/yk6Lepq2/ 您可以在此处查看此代码: https : //jsfiddle.net/yk6Lepq2/

Now when using a nuxt-link, normally it will scroll the page to the top, but since the layout has been changed and my application isn't using the initial body/html tag scrollbar it won't scroll the page to the top. 现在,当使用nuxt-link时,通常会将页面滚动到顶部,但是由于布局已更改并且我的应用程序未使用初始body / html标签滚动条,因此它不会将页面滚动到顶部。 I have been reading the NuxtjJs documentation but sadly I can't exactly find out how to change the target scrollbar to be scrolled. 我一直在阅读NuxtjJs文档,但遗憾的是我无法确切找到如何更改要滚动的目标滚动条。

I already put the following code in my nuxt.config.js but that doesn't help. 我已经在我的nuxt.config.js中放置了以下代码,但这无济于事。

router: {
    scrollBehavior: function (to, from, savedPosition) {
        return { x: 0, y: 0 }
    }
}

Is anybody here able to help me out with this problem? 这里有人可以帮助我解决这个问题吗? Any help is appreciated. 任何帮助表示赞赏。

Simply add this to the css of your body 只需将其添加到您的身体的CSS

body {
  ...
  overflow-y: hidden;
}

then in the container element for your content add the CSS property 然后在内容的容器元素中添加CSS属性

overflow-y: auto

that way, only the content side will scroll. 这样,只有内容方会滚动。 Other parts of the page won't scroll. 页面的其他部分将不会滚动。 In essence, you don't need javascript to do this. 本质上,您不需要使用JavaScript即可执行此操作。

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

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