MCPcopy Create free account
hub / github.com/codebucks27/react-portfolio-final / AnchorComponent

Function AnchorComponent

src/subComponents/Anchor.jsx:32–84  ·  view source on GitHub ↗
(props)

Source from the content-addressed store, hash-verified

30
31
32const AnchorComponent = (props) => {
33
34 const ref = useRef(null);
35 const hiddenRef = useRef(null);
36
37 useEffect(() => {
38
39 const handleScroll = () => {
40
41 let scrollPosition = window.pageYOffset;
42 let windowSize = window.innerHeight;
43 let bodyHeight = document.body.offsetHeight;
44
45 let diff = Math.max(bodyHeight - (scrollPosition + windowSize) )
46 //diff*100/scrollposition
47 let diffP = (diff * 100) / (bodyHeight - windowSize);
48
49 ref.current.style.transform = `translateY(${-diffP}%)`
50
51 if(window.pageYOffset > 5){
52 hiddenRef.current.style.display = 'none'
53 }else{
54 hiddenRef.current.style.display = 'block'
55
56 }
57 }
58
59 window.addEventListener('scroll', handleScroll)
60
61 return () => window.removeEventListener('scroll', handleScroll)
62
63
64 }, [])
65
66
67
68 return (
69 <Container>
70 <PreDisplay ref={hiddenRef} className='hidden'>
71
72 <Anchor width={70} height={70} fill='currentColor'/>
73 </PreDisplay>
74 <Slider ref={ref}>
75 {
76 [...Array(props.number)].map((x,id) => {
77 return <Link key={id} width={25} height={25} fill='currentColor' className="chain" />
78 })
79 }
80 <Anchor width={70} height={70} fill='currentColor'/>
81 </Slider>
82 </Container>
83 )
84}
85
86export default AnchorComponent

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected