|
@@ -3,26 +3,35 @@ import styles from './index.module.scss'
|
|
|
import { Swiper, SwiperSlide } from 'swiper/react'
|
|
import { Swiper, SwiperSlide } from 'swiper/react'
|
|
|
import 'swiper/css'
|
|
import 'swiper/css'
|
|
|
import 'swiper/css/effect-coverflow'
|
|
import 'swiper/css/effect-coverflow'
|
|
|
|
|
+import 'swiper/css/pagination'
|
|
|
import 'swiper/css/navigation'
|
|
import 'swiper/css/navigation'
|
|
|
-import { EffectCoverflow, Navigation } from 'swiper/modules'
|
|
|
|
|
-function SwiperComponent({ activeIndex, setActiveIndex }: { activeIndex: number, setActiveIndex: (index: number) => void }) {
|
|
|
|
|
|
|
+import { EffectCoverflow, Pagination, Navigation } from 'swiper/modules'
|
|
|
|
|
+function SwiperComponent({
|
|
|
|
|
+ activeIndex,
|
|
|
|
|
+ setActiveIndex
|
|
|
|
|
+}: {
|
|
|
|
|
+ activeIndex: number
|
|
|
|
|
+ setActiveIndex: (index: number) => void
|
|
|
|
|
+}) {
|
|
|
const swiperRef = useRef<any>(null)
|
|
const swiperRef = useRef<any>(null)
|
|
|
- const handleVideoClick = useCallback((index: number) => {
|
|
|
|
|
- setActiveIndex(index)
|
|
|
|
|
- }, [setActiveIndex])
|
|
|
|
|
-
|
|
|
|
|
- // 监听 activeIndex 变化:点击 bottom item 时同步 Swiper 跳转到对应 slide
|
|
|
|
|
|
|
+ // 是否点击bottom改变了activeIndex
|
|
|
|
|
+ const isInternalChange = useRef(false)
|
|
|
|
|
+ const listLength = myDataTemp.lifeList.length
|
|
|
|
|
+ const handleVideoClick = useCallback(
|
|
|
|
|
+ (index: number) => {
|
|
|
|
|
+ setActiveIndex(index)
|
|
|
|
|
+ console.log(index)
|
|
|
|
|
+ },
|
|
|
|
|
+ [setActiveIndex]
|
|
|
|
|
+ )
|
|
|
|
|
+ // 监听activeIndex变化
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
- const swiper = swiperRef.current?.swiper
|
|
|
|
|
- if (swiper) {
|
|
|
|
|
- const isLoop = myDataTemp.lifeList.length > 4
|
|
|
|
|
- if (isLoop) {
|
|
|
|
|
- swiper.slideToLoop(activeIndex, 300)
|
|
|
|
|
- } else {
|
|
|
|
|
- swiper.slideTo(activeIndex, 300)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }, [activeIndex])
|
|
|
|
|
|
|
+ if (!swiperRef.current) return
|
|
|
|
|
+ isInternalChange.current = false
|
|
|
|
|
+ const index = activeIndex + 3 < listLength ? activeIndex + 3 : activeIndex + 3 - listLength
|
|
|
|
|
+ console.log(index, activeIndex)
|
|
|
|
|
+ swiperRef.current.swiper.slideToLoop(index)
|
|
|
|
|
+ }, [activeIndex, listLength])
|
|
|
return (
|
|
return (
|
|
|
<div className={styles.SwiperComponent}>
|
|
<div className={styles.SwiperComponent}>
|
|
|
<Swiper
|
|
<Swiper
|
|
@@ -39,11 +48,13 @@ function SwiperComponent({ activeIndex, setActiveIndex }: { activeIndex: number,
|
|
|
depth: 240, // 控制了3d视角的深度
|
|
depth: 240, // 控制了3d视角的深度
|
|
|
modifier: 3
|
|
modifier: 3
|
|
|
}}
|
|
}}
|
|
|
- pagination={false}
|
|
|
|
|
- modules={[EffectCoverflow, Navigation]}
|
|
|
|
|
|
|
+ pagination={{ el: '.swiper-pagination', clickable: true }}
|
|
|
|
|
+ modules={[EffectCoverflow, Pagination, Navigation]}
|
|
|
className='swiper_container'
|
|
className='swiper_container'
|
|
|
onSlideChange={(swiper: any) => {
|
|
onSlideChange={(swiper: any) => {
|
|
|
- handleVideoClick(swiper.realIndex)
|
|
|
|
|
|
|
+ const index = swiper.realIndex - 3 >= 0 ? swiper.realIndex - 3 : swiper.realIndex + listLength - 3
|
|
|
|
|
+ isInternalChange.current = true
|
|
|
|
|
+ handleVideoClick(index)
|
|
|
}}
|
|
}}
|
|
|
onTransitionEnd={(swiper: any) => {
|
|
onTransitionEnd={(swiper: any) => {
|
|
|
const swiperInternal = swiper as { loopFix: () => void }
|
|
const swiperInternal = swiper as { loopFix: () => void }
|
|
@@ -52,9 +63,8 @@ function SwiperComponent({ activeIndex, setActiveIndex }: { activeIndex: number,
|
|
|
>
|
|
>
|
|
|
{myDataTemp.lifeList.map((item, index) => (
|
|
{myDataTemp.lifeList.map((item, index) => (
|
|
|
<SwiperSlide key={index}>
|
|
<SwiperSlide key={index}>
|
|
|
- <div
|
|
|
|
|
- className={`itemCard ${activeIndex === index ? 'itemCardActive' : ''}`}
|
|
|
|
|
- >
|
|
|
|
|
|
|
+ <div className={`itemCard ${activeIndex === index ? 'itemCardActive' : ''}`}>
|
|
|
|
|
+ {item.name}
|
|
|
<div className='itemImage'>
|
|
<div className='itemImage'>
|
|
|
<img className='itemImageImg' src={item?.imgSrc} alt='' />
|
|
<img className='itemImageImg' src={item?.imgSrc} alt='' />
|
|
|
<img
|
|
<img
|
|
@@ -67,6 +77,7 @@ function SwiperComponent({ activeIndex, setActiveIndex }: { activeIndex: number,
|
|
|
</SwiperSlide>
|
|
</SwiperSlide>
|
|
|
))}
|
|
))}
|
|
|
</Swiper>
|
|
</Swiper>
|
|
|
|
|
+ {/* <div className='swiper-pagination'></div> */}
|
|
|
|
|
|
|
|
<div className='leftArrow' onClick={() => swiperRef.current?.swiper?.slidePrev()}>
|
|
<div className='leftArrow' onClick={() => swiperRef.current?.swiper?.slidePrev()}>
|
|
|
<img src={require('../../../assets/img/A6_life_left.png')} alt='' />
|
|
<img src={require('../../../assets/img/A6_life_left.png')} alt='' />
|