快速导航固定栏开发-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)
posted @   Ly021  阅读(5)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示