componentDidMount() {
this.move();
}
skipToDep(e) {
let dom = document.getElementById(e); // 获取要跳至的字母节点
if (e === ‘#‘) {
this.props.scroller.scrollTo(0, 0);
} else {
this.props.scroller.scrollTo(0, -dom.offsetTop);
}
}
move() {
// 监听字母导航列表的touchmove事件
this.navigation.addEventListener(‘touchmove‘, e => {
const node = document.elementFromPoint(e.touches[0].clientX, e.touches[0].clientY); // 获取move时对应的节点
const reg = /^(#|[A-Z])/;
if(reg.test(node.innerText)) {
this.skipToDep(node.innerText);
}
});
}
原文地址:https://www.cnblogs.com/ljwk/p/9929993.html
时间: 2024-11-08 13:28:13