javascript - 如何使用机车库禁用智能手机上的粘性元素?
问题描述
我有一个关于 javascript 的问题。(我是新手)。我在 Webflow 项目中使用机车平滑滚动库。因为 Webflow 交互往往不能很好地与 locomotive 结合使用,所以我使用 locomotive 提供的功能来创建一个粘性元素。在移动设备上,我想禁用粘性效果。这是机车代码:
<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 分配了一个名为 #sticky1 的 ID。粘在视口顶部的 div 具有以下属性:
如何在移动设备上消除粘性效果?希望我的问题有意义!
亲切的问候,杰伦
解决方案
在初始化机车之前,您可以简单地使用 javascript 从 div 中删除 data-scroll-sticky 属性,例如:
if(isMobile) {
element.removeAttribute(data-scroll-sticky);
element.removeAttribute(data-scroll-target);
}
const locoScroll = new LocomotiveScroll({
推荐阅读
- python - 我很难找出为什么我得到这个索引超出范围错误
- r - RVest 太慢,试图优化拉动股票指标
- sql-server - 链接到 SQL Server 后 Access 数据库大小增加
- hyperledger-fabric - 如何在 Hyperledger Fabric 中插入共识
- r - 部分比例优势模型中的平均边际效应 (AME)
- javascript - 使用相同的 html 文件缓存 url,与查询字符串参数无关
- c# - 我可以从命令行通过 C# 文件运行 EditorConfig 吗?
- algorithm - 设计具有插入(键、值)、获取、删除和获取最后访问的键操作的数据结构,每个 O(1) 复杂度
- php - 通过 PHP 启动 node.js 脚本会禁用日志,权限问题显然
- c++ - C++ std::vector,静态初始化