Browse Source

切换防抖

liushengqiang 2 years ago
parent
commit
14def14be4
1 changed files with 10 additions and 4 deletions
  1. 10 4
      src/views/coursewarePlay/index.tsx

+ 10 - 4
src/views/coursewarePlay/index.tsx

@@ -518,6 +518,7 @@ export default defineComponent({
     ]
 
     const acitveTimer = ref()
+    const animationTimer =ref()
     // 轮播切换
     const handleSwipeChange = (index: number) => {
       if (popupData.activeIndex == index) return
@@ -525,6 +526,7 @@ export default defineComponent({
       popupData.activeIndex = index
       handleStop()
       clearTimeout(acitveTimer.value)
+      clearTimeout(animationTimer.value)
 
       const item = data.itemList[index]
       acitveTimer.value = setTimeout(
@@ -546,13 +548,17 @@ export default defineComponent({
                 item.videoEle?.play()
               })
             }
-            nextTick(() => {
-              effectIndex.value = Math.round(Math.random() * (effects.length - 1))
-            })
           }
         },
         item.isAnimation ? 800 : 0
       )
+      animationTimer.value = setTimeout(() => {
+        effectIndex.value = effectIndex.value + 1
+        if (effectIndex.value >= effects.length - 1) {
+          effectIndex.value = 0
+        }
+        // effectIndex.value = Math.round(Math.random() * (effects.length - 1))
+      }, 1000)
     }
 
     /** 是否有转场动画 */
@@ -560,9 +566,9 @@ export default defineComponent({
       const oldItem = data.itemList[index]
       const preItem = data.itemList[index - 1]
       const nextItem = data.itemList[index + 1]
+      oldItem && (oldItem.isAnimation = oldItem?.adviseStudyTimeSecond < 8 ? false : true)
       preItem && (preItem.isAnimation = oldItem.knowledgePointId == preItem.knowledgePointId && oldItem?.adviseStudyTimeSecond < 8 ? false : true)
       nextItem && (nextItem.isAnimation = oldItem.knowledgePointId == nextItem.knowledgePointId && oldItem?.adviseStudyTimeSecond < 8 ? false : true)
-      console.log(preItem?.isAnimation, nextItem?.isAnimation)
     }
 
     // 上一个知识点, 下一个知识点