我有一个关于javascript的问题。(我是新手)。我在Webflow项目中使用火车头平滑滚动库。因为Webflow交互往往不能很好地与火车头结合使用,所以我使用了火车头提供的功能来创建粘性元素。在手机上,我想禁用粘滞效果。这是火车头的代码:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/locomotive-scroll@3.5.4/dist/locomotive-scroll.css">
<script src="https://cdn.jsdelivr.net/npm/locomotive-scroll@4.1.1/dist/locomotive-scroll.min.js"></script>
<script>
const locoScroll = new LocomotiveScroll({
el: document.querySelector(".locomotive-scroll"),
smooth: true,
smartphone: {
smooth: true
},
tablet: {
smooth: true
},
smoothMobile: 1,
multiplier: 1.0,
});
</script>粘性元素的父div具有一个名为#ticky1的ID。粘贴到视口顶部的div具有以下属性:attributes
怎样才能在手机上消除粘性效果呢?希望我的问题有意义!
致以亲切的问候,杰伦
发布于 2021-11-11 12:03:17
在初始化火车头之前,您可以简单地使用javascript从div中删除data-scroll-sticky属性,例如:
if(isMobile) {
element.removeAttribute(data-scroll-sticky);
element.removeAttribute(data-scroll-target);
}
const locoScroll = new LocomotiveScroll({https://stackoverflow.com/questions/69271693
复制相似问题