Skip to content

Commit e896273

Browse files
committed
feat: 优化自动滚动
1 parent bc7476a commit e896273

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/client/page/comic/ImgControl.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const Control: React.FC<{}> = ({ children }) => {
6262
<Tooltip title="滤镜1" placement="top">
6363
<Filter1Icon
6464
className={classNames("bg-[#333] text-white", {
65-
["text-orange-300"]: filter === 1,
65+
["!text-orange-300"]: filter === 1,
6666
})}
6767
onClick={() => onClickFilter(1)}
6868
/>

src/client/page/comic/imgList.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ const HorizonImgList: React.FC<ImgListProps> = ({
317317
const [loading, setLoading] = useState(true);
318318
const [scrollingDone, setScrollingDone] = useState(false);
319319
const containerRef = useRef<HTMLDivElement>(null);
320+
const { autoScroll } = useComicContext();
320321
useWatchComicPositionChange(!loading && scrollingDone, onVisitPosition);
321322

322323
const { onLoad: onImgLoad } = useImgLoadAutoScrollIntoView(
@@ -358,6 +359,28 @@ const HorizonImgList: React.FC<ImgListProps> = ({
358359
return () => {};
359360
}, []);
360361

362+
useEffect(() => {
363+
const container = containerRef.current;
364+
let hasbreak = false;
365+
if (autoScroll && container) {
366+
function scroll() {
367+
if (hasbreak) {
368+
return;
369+
}
370+
if (containerRef.current) {
371+
containerRef.current.scrollLeft -= 4;
372+
requestAnimationFrame(scroll);
373+
}
374+
}
375+
376+
requestAnimationFrame(scroll);
377+
return () => {
378+
hasbreak = true;
379+
};
380+
}
381+
return () => {};
382+
}, [autoScroll]);
383+
361384
const reverseImgList = useMemo(() => {
362385
return [...imgList].reverse();
363386
}, [imgList]);
@@ -374,7 +397,7 @@ const HorizonImgList: React.FC<ImgListProps> = ({
374397
return (
375398
<div
376399
key={index}
377-
className="flex-shrink-0 px-2 bg-gray-500 h-[100vh] bg-gray-100 ml-4 border border-box flex items-center"
400+
className="pt-3 pb-5 flex-shrink-0 px-2 h-[100vh] bg-gray-100 border-x border-box flex items-center"
378401
>
379402
<img
380403
onLoad={onImgLoad}

0 commit comments

Comments
 (0)