1.需求分析:点击左边固定列表,页面滑到某个区域
代码精华,获取元素的标签一般为id的唯一值
scrollIntoView (index) {
const dom = document.getElementById(`course-category-${index}`)
if (dom) dom.scrollIntoView({ block: 'start', behavior: 'smooth' })
},
主要应用到设计的scrollIntoView的知识点
behavior :定义动画过渡效果,值为auto或smooth。
block :定义垂直方向的对齐,值为start/center/end/nearest。
inline :定义水平方向的对齐,值为start/center/end/nearest。
这样就能通过左边的选项点击移动到其中的区域