scrollTo的behavior
时间: 2024-01-02 15:03:13 浏览: 121
scrollTo的behavior是用来设置滚动的行为的属性。它可以设置为"smooth",以实现平滑滚动的效果。在JavaScript中,使用scrollTo方法时,可以通过传入一个对象,设置top和behavior属性来实现平滑滚动的效果。然而,在移动端中,由于一些兼容性问题,使用js自带的scrollTo方法时,behavior属性的"smooth"值可能会失效。为了解决这个问题,可以引入smoothscroll-polyfill库,并在组件创建时调用smoothscroll.polyfill()方法来解决移动端scrollTo的behavior: "smooth"无效的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [scrollTo滚动到指定位置或指定元素的位置、平滑滚动,以及offsetTop的使用](https://blog.csdn.net/lingliu0824/article/details/115338509)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [解决移动端scrollTo({behavior: “smooth“})滑动效果失效的问题](https://blog.csdn.net/liucai1018/article/details/116795115)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文