如何将滚动滚动到没有垂直滚动条的页面中的底部按钮?
我对顶部和底部按钮进行了滚动,该按钮可以使用户滚动到顶部并在单击时滚动到底部。目前,如果按钮是滚动图标/按钮,则该按钮将出现在仅包含垂直滚动条的页面中,并且在没有垂直滚动条的页面中消失。但是,如果按钮更改为滚动到底部图标/按钮,则该按钮将出现在包含卷轴且无卷轴的两个页面中。如何使滚动到底部按钮消失在不包含垂直卷轴的页面中?希望有人可以帮助我。
scrolltopop.vue
<template>
<div v-scroll="onScroll" >
<v-btn v-if = "!isVisible"
fab fixed bottom right color="primary" @click="toBottom">
<v-icon>mdi-arrow-down-bold-box-outline</v-icon>
</v-btn>
<v-btn v-else
fab fixed bottom right color="primary" @click="toTop">
<v-icon>mdi-arrow-up-bold-box-outline</v-icon>
</v-btn>
</div>
</template>
<script>
export default{
data () {
return {
isVisible: false,
position: 0,
}
},
methods: {
onScroll () {
this.isVisible = window.scrollY > 50
},
toTop () {
this.position = window.scrollY
window.scrollTo({
top: 0,
left: 0,
behavior: 'smooth'
})
},
toBottom(){
let pos = this.position > 0 ? this.position: document.body.scrollHeight
window.scrollTo({
top: pos,
behavior: 'smooth'
})
},
}
}
</script>
default.vue
<script>
export default {
name: "DefaultLayout",
data() {
return {
hasScroll: false
};
},
methods: {
hasVerticalScroll() {
this.hasScroll = document.body.offsetHeight > window.innerHeight;
}
}
}
</script>
<template>
<v-app dark v-scroll="hasVerticalScroll">
<ScrollToTop v-if="hasScroll"></ScrollToTop>
</v-app>
</template>
I made a scroll to top and bottom button, which allow users to scroll to top and scroll to bottom when it is clicked. As for now , if the button is scroll-to-top icon/button, the button will appear in pages that contain vertical scrollbar only and disappear in pages that do not have vertical scrollbar. However , if the button changes to scroll-to-bottom icon/ button, the button will appear in both pages that contain scrollbar and no scrollbar. How do i make scroll to bottom button disappear in a page that do not contain vertical scrollbar? Hope someone could help me on this.
ScrollToTop.vue
<template>
<div v-scroll="onScroll" >
<v-btn v-if = "!isVisible"
fab fixed bottom right color="primary" @click="toBottom">
<v-icon>mdi-arrow-down-bold-box-outline</v-icon>
</v-btn>
<v-btn v-else
fab fixed bottom right color="primary" @click="toTop">
<v-icon>mdi-arrow-up-bold-box-outline</v-icon>
</v-btn>
</div>
</template>
<script>
export default{
data () {
return {
isVisible: false,
position: 0,
}
},
methods: {
onScroll () {
this.isVisible = window.scrollY > 50
},
toTop () {
this.position = window.scrollY
window.scrollTo({
top: 0,
left: 0,
behavior: 'smooth'
})
},
toBottom(){
let pos = this.position > 0 ? this.position: document.body.scrollHeight
window.scrollTo({
top: pos,
behavior: 'smooth'
})
},
}
}
</script>
Default.vue
<script>
export default {
name: "DefaultLayout",
data() {
return {
hasScroll: false
};
},
methods: {
hasVerticalScroll() {
this.hasScroll = document.body.offsetHeight > window.innerHeight;
}
}
}
</script>
<template>
<v-app dark v-scroll="hasVerticalScroll">
<ScrollToTop v-if="hasScroll"></ScrollToTop>
</v-app>
</template>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用jQuery,这将指示何时存在AA垂直滚动条。从这里,您可以控制是否显示或隐藏按钮。
Using jQuery this will indicate when a a vertical scroll bar is present. From here you can control whether to show or hide the button.
尝试使用此
情况,可以为您的卷轴托普(Scrolltotop)做。
Try this out
The same case you can do for your scrollToTop.