Skip to content

Commit 9710656

Browse files
committed
Add smooth scrolling effect for hash links in HackathonList component
1 parent 6e72b39 commit 9710656

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/Page/OpportunitiesHub/HackathonList.jsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useState } from 'react';
22
import styled from 'styled-components';
3+
import { useEffect } from 'react';
34
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
45
import { faFlag, faMapMarkerAlt, faCalendarAlt, faShareAlt } from '@fortawesome/free-solid-svg-icons';
56

@@ -821,6 +822,21 @@ const HackathonList = () => {
821822
const [monthFilter, setMonthFilter] = useState('');
822823
const [domainFilter, setDomainFilter] = useState('');
823824

825+
useEffect(() => {
826+
if (window.location.hash) {
827+
const id = window.location.hash.substring(1);
828+
const el = document.getElementById(id);
829+
if (el) {
830+
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
831+
el.style.boxShadow = '0 0 0 4px #00a6fb, 0 0 20px #00a6fb';
832+
el.style.transition = 'box-shadow 0.5s';
833+
setTimeout(() => {
834+
el.style.boxShadow = '';
835+
}, 2000);
836+
}
837+
}
838+
}, []);
839+
824840
const filteredHackathons = hackathons.filter((hackathon) => {
825841
const matchesLocation = locationFilter
826842
? hackathon.location.toLowerCase().includes(locationFilter.toLowerCase())

0 commit comments

Comments
 (0)