首页 > 解决方案 > scrollTo(target, options) 在移动设备中不起作用。(机车卷轴)

问题描述

我面临一个奇怪的问题。在桌面上,一切正常,但是当我切换到移动设备时,发生了一些奇怪的事情,不知道为什么。scrollTo(target, options) 根本不起作用。在桌面水平模式上,对于移动设备,我已将其关闭,并且在移动设备上也关闭了平滑。

我的代码:

const lscroll = new LocomotiveScroll({
  el: document.querySelector('[data-scroll-container]'),
  smooth: true,
  repeat: false,
  getDirection: true,
  direction: 'horizontal',
  tablet: {
    smooth: false,
    direction: "vertical"
  },
  smartphone: {
    smooth: false,
    direction: "vertical"
  },
});

我也尝试过使用平滑真实的移动设备,但没有发生任何事情。请帮我解决一下这个。TIA

标签: javascriptsmooth-scrollinglocomotivejslocomotive-scroll

解决方案


像这样在html文件中使用它

<a href="#here" data-scroll-to>
    scroll to explore
 </a>


..

..

 <section  id="here">`enter code here`  </section>

如果机车滚动在 JS 中正确初始化,它应该可以工作


推荐阅读