Vue3 让滚动条到底部&顶部
【代码】Vue3 让滚动条到底部&顶部。
·
<div ref="scrollDiv">
</div>
<script setup>
import { ref, reactive, onMounted, defineProps, nextTick } from 'vue'
const scrollDiv = ref(null)
onMounted(() => {
//划动回到顶部
nextTick(() => {
let scrollElem = scrollDiv.value;
scrollElem.scrollTo({ top: 0, behavior: 'smooth' });
});
// 滚动到底部
nextTick(() => {
let scrollElem = scrollDiv.value;
scrollElem.scrollTo({ top: scrollElem.scrollHeight, behavior: 'smooth' });
});
})
</script>
更多推荐
已为社区贡献2条内容
所有评论(0)