指定盒子滚动到合适区域

  1. const returnEle = document.querySelector('.box');
  2. if (!!returnEle) {
  3. returnEle.scrollIntoView({
  4. behavior: 'smooth',
  5. });
  6. }

Element.scrollIntoView

兼容问题:ios(safari)中不生效

image.png
原因:不兼容safari
解决:smooth-ployfill

参考:

https://stackoverflow.com/questions/65552682/scrollintoview-is-not-working-as-expected-in-safari-browser
https://juejin.cn/post/7026274240349339685