-
Notifications
You must be signed in to change notification settings - Fork 663
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #261 from hepengwei/feat_he
新增鼠标Hover交互效果3
- Loading branch information
Showing
24 changed files
with
146 additions
and
3 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions
41
src/pages/html/InteractiveDesign/components/MouseHover3/Card.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React, { useRef, useEffect, useCallback } from "react"; | ||
import styles from "./card.module.scss"; | ||
|
||
interface CardProps { | ||
url: string; | ||
} | ||
|
||
const Card = (props: CardProps) => { | ||
const { url } = props; | ||
const containerRef = useRef<HTMLDivElement>(null); | ||
|
||
const onMouseMove = useCallback((e: MouseEvent) => { | ||
if (containerRef.current) { | ||
const { clientX, clientY } = e; | ||
const { x, y } = containerRef.current.getBoundingClientRect(); | ||
containerRef.current.setAttribute( | ||
"style", | ||
`--url: url("${url}"); --x: ${clientX - x}px; --y: ${clientY - y}px` | ||
); | ||
} | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (containerRef.current && url) { | ||
containerRef.current.setAttribute("style", `--url: url("${url}")`); | ||
} | ||
window.addEventListener("mousemove", onMouseMove); | ||
|
||
return () => { | ||
window.removeEventListener("mousemove", onMouseMove); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<div className={styles.container} ref={containerRef}> | ||
<div className={styles.content} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Card; |
62 changes: 62 additions & 0 deletions
62
src/pages/html/InteractiveDesign/components/MouseHover3/card.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
.container { | ||
$borderRadius: 24px; | ||
width: 300px; | ||
height: 424px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
border-radius: $borderRadius; | ||
cursor: pointer; | ||
overflow: hidden; | ||
position: relative; | ||
|
||
&::before { | ||
content: ""; | ||
opacity: 0; | ||
transition: opacity 0.6s; | ||
position: absolute; | ||
inset: 0; | ||
border-radius: $borderRadius; | ||
background: conic-gradient(#03a9f4, #e91e63, #9c27b0, #ff5722, #03a9f4); | ||
mask: radial-gradient( | ||
circle at var(--x) var(--y), | ||
#000, | ||
#000, | ||
transparent, | ||
transparent, | ||
transparent | ||
); | ||
} | ||
|
||
&:hover { | ||
&::before { | ||
opacity: 1; | ||
} | ||
} | ||
|
||
.content { | ||
border-radius: $borderRadius; | ||
overflow: hidden; | ||
position: absolute; | ||
inset: 3px; | ||
|
||
&::before, | ||
&::after { | ||
content: ""; | ||
position: absolute; | ||
background: var(--url); | ||
background-size: cover; | ||
background-position: center; | ||
border-radius: $borderRadius; | ||
} | ||
|
||
&::before { | ||
inset: 0; | ||
filter: blur(20px); | ||
} | ||
|
||
&::after { | ||
inset: 40px; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/pages/html/InteractiveDesign/components/MouseHover3/index.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.container { | ||
width: 100%; | ||
height: 560px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
|
||
.content { | ||
width: 70%; | ||
max-width: 1300px; | ||
min-width: 900px; | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/pages/html/InteractiveDesign/components/MouseHover3/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React, { useRef, useEffect, useCallback } from "react"; | ||
import Card from "./Card"; | ||
import car1 from "images/html/car1.png"; | ||
import car2 from "images/html/car2.png"; | ||
import car3 from "images/html/car3.png"; | ||
import styles from "./index.module.scss"; | ||
|
||
const cardList = [car1, car2, car3]; | ||
|
||
const MouseHover3 = () => { | ||
return ( | ||
<div className={styles.container}> | ||
<div className={styles.content}> | ||
{cardList.map((url: string, index: number) => ( | ||
<Card url={url} key={index} /> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default MouseHover3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters