|
|
@@ -32,6 +32,9 @@ function ModalTxt({
|
|
|
const originRef = useRef<any>(null)
|
|
|
const translateRef = useRef<any>(null)
|
|
|
const contentRef = useRef<any>(null)
|
|
|
+ const originStartX = useRef<number>(0)
|
|
|
+ const translateStartX = useRef<number>(0)
|
|
|
+ const contentStartX = useRef<number>(0)
|
|
|
|
|
|
useEffect(() => {
|
|
|
if (selectedTab !== 0) {
|
|
|
@@ -52,47 +55,108 @@ function ModalTxt({
|
|
|
const OriContent = document.getElementById('OriContent')
|
|
|
const introContent = document.getElementById('introContent')
|
|
|
const TransContent = document.getElementById('TransContent')
|
|
|
+ console.log(TransContent, 'TransContent')
|
|
|
+ // // 新增滚动同步逻辑
|
|
|
+ let isSyncing = false
|
|
|
+
|
|
|
+ const syncScroll = (source: HTMLElement, target: HTMLElement) => {
|
|
|
+ if (!isSyncing) {
|
|
|
+ isSyncing = true
|
|
|
+ target.scrollTop = source.scrollTop
|
|
|
+ setTimeout(() => isSyncing = false, 100)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const handleOriScroll = () => {
|
|
|
+ if (OriContent && TransContent) {
|
|
|
+ // syncScroll(OriContent, TransContent)
|
|
|
+ TransContent.scrollTop = OriContent.scrollTop
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const handleTransScroll = () => {
|
|
|
+ if (TransContent && OriContent) {
|
|
|
+ // syncScroll(TransContent, OriContent)
|
|
|
+ OriContent.scrollTop = TransContent.scrollTop
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // if (OriContent) {
|
|
|
+ // OriContent.addEventListener('scroll', handleOriScroll)
|
|
|
+ // }
|
|
|
+ // if (TransContent) {
|
|
|
+ // TransContent.addEventListener('scroll', handleTransScroll)
|
|
|
+ // }
|
|
|
+
|
|
|
+ // return () => {
|
|
|
+ // if (OriContent) {
|
|
|
+ // OriContent.removeEventListener('scroll', handleOriScroll)
|
|
|
+ // }
|
|
|
+ // if (TransContent) {
|
|
|
+ // TransContent.removeEventListener('scroll', handleTransScroll)
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ const handleStart = (e: TouchEvent, startX: any) => {
|
|
|
+ startX.current = e.touches[0].clientX
|
|
|
+ }
|
|
|
const handlerOri = (e: TouchEvent) => {
|
|
|
// e.stopPropagation()
|
|
|
- const deltaX = e.touches[0].clientX
|
|
|
- if (OriContent) {
|
|
|
- OriContent.scrollTop += deltaX
|
|
|
+ const deltaX = e.touches[0].clientX - originStartX.current
|
|
|
+
|
|
|
+ if (OriContent && TransContent) {
|
|
|
+ OriContent.scrollTop += deltaX * 0.06
|
|
|
+ console.log(OriContent.scrollTop, 'scrollTop')
|
|
|
+ TransContent.scrollTop = OriContent.scrollTop
|
|
|
}
|
|
|
}
|
|
|
- const handler = (e: TouchEvent) => {
|
|
|
+
|
|
|
+ const handlerTrans = (e: TouchEvent) => {
|
|
|
// e.stopPropagation()
|
|
|
- const deltaX = e.touches[0].clientX
|
|
|
- if (tooltipContent) {
|
|
|
- tooltipContent.scrollTop += deltaX
|
|
|
+ const deltaX = e.touches[0].clientX - translateStartX.current
|
|
|
+
|
|
|
+ if (TransContent && OriContent) {
|
|
|
+ TransContent.scrollTop += deltaX * 0.06
|
|
|
+ OriContent.scrollTop = TransContent.scrollTop
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
// 处理触摸开始事件
|
|
|
|
|
|
if (OriContent) {
|
|
|
+ OriContent.addEventListener('touchstart', (e) => { handleStart(e, originStartX) })
|
|
|
OriContent.addEventListener('touchmove', handlerOri)
|
|
|
- return () => {
|
|
|
- OriContent.removeEventListener('touchmove', handlerOri) // 保持参数一致
|
|
|
- }
|
|
|
- }
|
|
|
- if (tooltipContent) {
|
|
|
- tooltipContent.addEventListener('touchmove', handler)
|
|
|
- return () => {
|
|
|
- tooltipContent.removeEventListener('touchmove', handler) // 保持参数一致
|
|
|
- }
|
|
|
- }
|
|
|
- if (introContent) {
|
|
|
- introContent.addEventListener('touchmove', handler)
|
|
|
- return () => {
|
|
|
- introContent.removeEventListener('touchmove', handler) // 保持参数一致
|
|
|
- }
|
|
|
+ OriContent.addEventListener('scroll', handleOriScroll)
|
|
|
}
|
|
|
+ // if (tooltipContent) {
|
|
|
+ // tooltipContent.addEventListener('touchmove', handler)
|
|
|
+ // return () => {
|
|
|
+ // tooltipContent.removeEventListener('touchmove', handler) // 保持参数一致
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // if (introContent) {
|
|
|
+ // introContent.addEventListener('touchmove', handler)
|
|
|
+ // return () => {
|
|
|
+ // introContent.removeEventListener('touchmove', handler) // 保持参数一致
|
|
|
+ // }
|
|
|
+ // }
|
|
|
if (TransContent) {
|
|
|
- TransContent.addEventListener('touchmove', handler)
|
|
|
+ console.log(TransContent, 'TransContent')
|
|
|
+ TransContent.addEventListener('touchstart', (e) => { handleStart(e, translateStartX) })
|
|
|
+ TransContent.addEventListener('touchmove', handlerTrans)
|
|
|
+ TransContent.addEventListener('scroll', handleTransScroll)
|
|
|
+ }
|
|
|
+ if (OriContent && TransContent) {
|
|
|
return () => {
|
|
|
- TransContent.removeEventListener('touchmove', handler) // 保持参数一致
|
|
|
+ OriContent.removeEventListener('touchstart', (e) => { handleStart(e, originStartX) })
|
|
|
+ OriContent.removeEventListener('touchmove', handlerOri) // 保持参数一致
|
|
|
+ OriContent.removeEventListener('scroll', handleOriScroll)
|
|
|
+ TransContent.removeEventListener('touchstart', (e) => { handleStart(e, translateStartX) })
|
|
|
+ TransContent.removeEventListener('touchmove', handlerTrans) // 保持参数一致
|
|
|
+ TransContent.removeEventListener('scroll', handleTransScroll)
|
|
|
}
|
|
|
}
|
|
|
- }, [])
|
|
|
+
|
|
|
+ }, [selectedTab])
|
|
|
|
|
|
|
|
|
//动态加入a标签
|
|
|
@@ -107,12 +171,16 @@ function ModalTxt({
|
|
|
define: string
|
|
|
inset: string
|
|
|
}) => {
|
|
|
+ const dragFlag = useRef(false); // 新增拖拽标志位
|
|
|
+
|
|
|
const handleClick = () => {
|
|
|
+ if (dragFlag.current) return; // 如果是拖拽操作则直接返回
|
|
|
setActiveAId(index)
|
|
|
setShowTooltip(index)
|
|
|
const tooltip = document.querySelector('.ant-tooltip') as HTMLElement
|
|
|
if (isMobiileFu() && tooltip) tooltip.style.inset = inset
|
|
|
}
|
|
|
+
|
|
|
return (
|
|
|
<Tooltip
|
|
|
title={
|
|
|
@@ -154,7 +222,15 @@ function ModalTxt({
|
|
|
<a
|
|
|
key={index}
|
|
|
className={activeAId === index ? 'active' : ''}
|
|
|
- onTouchEnd={handleClick}
|
|
|
+ onTouchStart={() => dragFlag.current = false} // 触摸开始时重置标志位
|
|
|
+ onTouchMove={() => dragFlag.current = true} // 检测到移动时标记为拖拽
|
|
|
+ onTouchEnd={(e) => {
|
|
|
+ if (!dragFlag.current) { // 只有非拖拽操作才处理
|
|
|
+ handleClick();
|
|
|
+ }
|
|
|
+ e.preventDefault();
|
|
|
+ e.stopPropagation();
|
|
|
+ }}
|
|
|
onClick={handleClick}
|
|
|
>
|
|
|
{word}
|