168 字
1 分钟
使用css实现滚动到页面对应的位置
2020-10-29

本文同步自 CSDN · 清阿哥,原文发布于 2020-10-29。

废话不多说先上代码

<div class="back-top-item" @click="turnFeeConsultation">
<div class="feeConsultation"></div>
<p class="text">收费咨询</p>
</div>
turnFeeConsultation() {
this.$nextTick(() =>
document.getElementsByClassName('paidConsultation')[0].scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'nearest' });
});
}

scrolIintoView 布尔值参数

  • scrollintoView(true) 或者scrollIntoView()相当于scrollIntoViewOptions: {block: “start”, inline: “nearest”}
  • scrollintoView(false) 相当于scrollIntoViewOptions: {block: “end”, inline: “nearest”}

scrolIintoView 布对象参数

  • behavior(可选)定义动画过渡效果, “auto” 瞬间跳转(没有动画效果)或 “smooth”(由动画效果平滑的到指定位置) 之一。默认为 “auto”
  • block(可选)定义垂直方向的对齐, “start”, “center”, “end”, 或 “nearest”之一。默认为 “start”。
  • inline(可选)定义水平方向的对齐, “start”, “center”, “end”, 或 “nearest”之一。默认为 “nearest”
使用css实现滚动到页面对应的位置
https://qingge-cabana.vercel.app/posts/使用css实现滚动到页面对应的位置-109351935/
作者
清阿哥
发布于
2020-10-29
许可协议
CC BY-NC-SA 4.0

评论 待开启

评论基于 GitHub Discussions(Giscus)。仓库推送并开启 Discussions 后,在 giscus.app 获取 repoId / categoryId ,填入 src/config.tsgiscusConfig 即可。

  • 目标仓库: HHQ-666/qingge-blog
  • 详细步骤见项目 docs/DEPLOY.md 第二节