期望点击按钮或其他操作时可以滚动到底部
方法:
scrollToBottom(){
this.$nextTick(() => {
var height = $("#scrollBox")[0].scrollHeight - $(window).height();
$("#scrollBox").scrollTop(height);
});
}
完整代码:
<template>
<div id="scrollBox">
<div @click="scrollToBottom">点击滑动到底部</div>
<div style="height:1500px;background:pink;">内容高1500</div>
</div>
</template>
<script>
import $ from "jquery";
export default {
data(){
return{}
},
methods:{
scrollToBottom(){
this.$nextTick(() => {
var height = $("#scrollBox")[0].scrollHeight - $(window).height();
$("#scrollBox").scrollTop(height);
});
}
}
}
</script>
<style>
#scrollBox {
height: 100vh;
overflow-y: auto;
}
</style>
|