快速导航固定栏开发-2
功能是能够点击导航栏的字母快速对应到相应的标题栏,手指拖动时候也可以去绑定切换对应的导航栏字母
步骤:
1、给导航栏shortcut绑定@touchstart.stop.prevent="onShortcutTouchStart“还有touchmove和touchend,这里加上stop和prevent是为了阻止浏览器自带的默认行为。然后在use-shortcut.js中定义onShortcutTouchStart的钩子函数:
function onShortcutTouchStart(e) {
}
return {
onShortcutTouchStart
}
然后在index-list接收钩子函数
const { onShortcutTouchStart } = useShortcut(props)
再通过setup()函数return到template中
2.获取index的索引
function onShortcutTouchStart(e) {
const anchorIndex = parseInt(e.target.dataset.index)
}
在li中加入属性
:data-index="index"
传出groupRef
useShortcut(groupRef)
然后计算目标滚动元素:
const targetEl = groupRef.value.children[anchorIndex]
然后要在scroll中返回出scroll,因为要调用到BScroll中方法
获取到scroll的值然后调用scrollToElement就可以实现
const scroll = scrollRef.value.scroll
scroll.scrollToElement(targetEl, 0)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?