This is an automated email from the ASF dual-hosted git repository.

luzhijing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris-website.git


The following commit(s) were added to refs/heads/master by this push:
     new 02fd47c90a6 (fix) fix first-page tabs animation bug (#376)
02fd47c90a6 is described below

commit 02fd47c90a670f62e98b6a14cc0def1187e55ced
Author: hututu <53259809+hututu...@users.noreply.github.com>
AuthorDate: Fri Dec 29 15:32:43 2023 +0800

    (fix) fix first-page tabs animation bug (#376)
---
 src/hooks/use-animation-frame.ts | 19 +++++++++++--------
 src/pages/index.tsx              |  4 +++-
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/hooks/use-animation-frame.ts b/src/hooks/use-animation-frame.ts
index 34b805f7fe1..eb9cceeedd5 100644
--- a/src/hooks/use-animation-frame.ts
+++ b/src/hooks/use-animation-frame.ts
@@ -11,21 +11,24 @@ export const useAnimationFrame = (callback, stop) => {
      */
 
     React.useEffect(() => {
-        console.log(stop);
-        if (stop) {
-            if (requestRef.current) return () => 
cancelAnimationFrame(requestRef.current);
-            return;
-        }
-
         const animate = time => {
             if (previousTimeRef.current !== undefined) {
                 const deltaTime = time - previousTimeRef.current;
                 callback(deltaTime);
             }
             previousTimeRef.current = time;
+            if (requestRef.current) cancelAnimationFrame(requestRef.current);
+            if (!stop) requestRef.current = requestAnimationFrame(animate);
+        };
+
+        if (!stop) {
             requestRef.current = requestAnimationFrame(animate);
+        }
+
+        return () => {
+            if (requestRef.current) {
+                cancelAnimationFrame(requestRef.current);
+            }
         };
-        requestRef.current = requestAnimationFrame(animate);
-        return () => cancelAnimationFrame(requestRef.current);
     }, [stop]); // Make sure the effect runs only once
 };
diff --git a/src/pages/index.tsx b/src/pages/index.tsx
index e7b29890780..70c15a5b7bc 100644
--- a/src/pages/index.tsx
+++ b/src/pages/index.tsx
@@ -480,7 +480,9 @@ export default function Home(): JSX.Element {
                 });
                 return 0;
             }
-            return prevCount + 0.4;
+            if (deltaTime > 100) return prevCount;
+
+            return prevCount + deltaTime * 0.01;
         });
     }, stop);
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to