|
@@ -123,22 +123,8 @@ function GoodsInfo({ isOpen, id, closePage }: Props) {
|
|
|
const [barrageAll, setBarrageAll] = useState<A2BarrageType[]>([]);
|
|
|
const barrMoveRef = useRef<HTMLDivElement>(null);
|
|
|
const [barrInd, setBarrInd] = useState(0);
|
|
|
- const barrIndRef = useRef(0);
|
|
|
- const barrTimeRef = useRef(0);
|
|
|
const barrMoveRefKill = useRef<any>(null);
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- if (barrageAll.length) {
|
|
|
- // 开启定时器
|
|
|
- barrTimeRef.current = window.setInterval(() => {
|
|
|
- let num = barrIndRef.current + 1;
|
|
|
- if (num >= barrageAll.length) num = 0;
|
|
|
- setBarrInd(num);
|
|
|
- barrIndRef.current = num;
|
|
|
- }, 17000);
|
|
|
- }
|
|
|
- }, [barrageAll.length]);
|
|
|
-
|
|
|
// 每次弹幕的索引变化的时候
|
|
|
useEffect(() => {
|
|
|
window.setTimeout(() => {
|
|
@@ -159,11 +145,16 @@ function GoodsInfo({ isOpen, id, closePage }: Props) {
|
|
|
duration: 16,
|
|
|
ease: "none",
|
|
|
x: endNum,
|
|
|
+ onComplete: () => {
|
|
|
+ let num = barrInd + 1;
|
|
|
+ if (num >= barrageAll.length) num = 0;
|
|
|
+ setBarrInd(num);
|
|
|
+ },
|
|
|
}
|
|
|
);
|
|
|
}
|
|
|
}, 200);
|
|
|
- }, [barrInd]);
|
|
|
+ }, [barrInd, barrageAll.length]);
|
|
|
|
|
|
// 通过id获取详情
|
|
|
const getDataFu = useCallback(
|
|
@@ -259,7 +250,6 @@ function GoodsInfo({ isOpen, id, closePage }: Props) {
|
|
|
useEffect(() => {
|
|
|
getDataFu(id);
|
|
|
return () => {
|
|
|
- clearInterval(barrTimeRef.current);
|
|
|
barrMoveRefKill.current?.kill();
|
|
|
};
|
|
|
}, [getDataFu, id]);
|