mirror of
https://github.com/trafficlunar/blockmatic.git
synced 2026-06-28 14:44:12 +00:00
feat: add hover effect to image and change image based on theme
This commit is contained in:
parent
090609a6fd
commit
8a43d9978b
4 changed files with 59 additions and 7 deletions
49
src/components/home/AppPreview.tsx
Normal file
49
src/components/home/AppPreview.tsx
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import { useContext, useState } from "react";
|
||||
import { ThemeContext } from "@/context/Theme";
|
||||
|
||||
function AppPreview() {
|
||||
const { isDark } = useContext(ThemeContext);
|
||||
|
||||
const [leaving, setLeaving] = useState(true);
|
||||
const [transform, setTransform] = useState("");
|
||||
|
||||
const onMouseEnter = () => {
|
||||
setLeaving(false);
|
||||
};
|
||||
|
||||
const onMouseLeave = () => {
|
||||
setLeaving(true);
|
||||
setTransform("rotateX(0deg) rotateY(0deg)");
|
||||
};
|
||||
|
||||
const onMouseMove = (e: React.MouseEvent) => {
|
||||
const rect = e.currentTarget.getBoundingClientRect();
|
||||
|
||||
const x = e.clientX - rect.left;
|
||||
const y = e.clientY - rect.top;
|
||||
|
||||
const centerX = rect.width / 2;
|
||||
const centerY = rect.height / 2;
|
||||
|
||||
const rotateX = ((y - centerY) / centerY) * 10;
|
||||
const rotateY = ((centerX - x) / centerX) * 10;
|
||||
|
||||
setTransform(`rotateX(${rotateX}deg) rotateY(${rotateY}deg)`);
|
||||
};
|
||||
|
||||
return (
|
||||
<img
|
||||
src={isDark ? "/blockmatic_screenshot_dark.png" : "/blockmatic_screenshot_light.png"}
|
||||
alt="app preview"
|
||||
onMouseEnter={onMouseEnter}
|
||||
onMouseLeave={onMouseLeave}
|
||||
onMouseMove={onMouseMove}
|
||||
className={`w-[90%] rounded-xl mt-32 border border-zinc-700 ${
|
||||
leaving ? "transition-transform duration-500 ease-in-out" : "duration-100 ease-out"
|
||||
}`}
|
||||
style={{ transform }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default AppPreview;
|
||||
Loading…
Add table
Add a link
Reference in a new issue