From ae9c183a64cd7c9818181fdfe5d54a228191d4e5 Mon Sep 17 00:00:00 2001 From: Blinko Date: Sat, 30 Nov 2024 20:14:56 +0800 Subject: [PATCH] fix: imporve virtual card #206 --- src/pages/review.tsx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/pages/review.tsx b/src/pages/review.tsx index 3d06194b..8035ff6a 100644 --- a/src/pages/review.tsx +++ b/src/pages/review.tsx @@ -2,7 +2,8 @@ import React, { useEffect, useRef, useState } from 'react'; import { Swiper, SwiperSlide, } from "swiper/react"; import "swiper/css"; import "swiper/css/effect-cards"; -import { EffectCards } from 'swiper/modules'; +import { EffectCards, Virtual } from 'swiper/modules'; +import 'swiper/css/virtual'; import '../styles/swiper-cards.css' import { observer } from 'mobx-react-lite'; import { RootStore } from '@/store'; @@ -59,22 +60,27 @@ const App = observer(() => { swiperRef.current = swiper; }} onSlideChange={(swiper) => store.handleSlideChange(swiper)} - onReachEnd={e => { }} effect={"cards"} grabCursor={true} - modules={[EffectCards]} + modules={[EffectCards, Virtual]} className="mt-10 md:mt-4 w-[300px] h-[380px] md:w-[350px] md:h-[520px]" allowSlideNext={true} allowSlidePrev={true} touchRatio={1} resistance={true} resistanceRatio={0.5} - slidesPerView={1} centeredSlides={true} + virtual={{ + enabled: true, + slides: blinko.dailyReviewNoteList.value ?? [], + cache: true, + addSlidesBefore: 1, + addSlidesAfter: 1, + }} > { blinko.dailyReviewNoteList.value?.map((i, index) => ( - +
{dayjs(i.createdAt).fromNow()}