Add smooth scrolling to YouTube cards when circle is clicked

This commit is contained in:
Chigozirim Igweamaka 2024-06-30 14:25:14 +01:00
parent 7c784d6384
commit 3ffa381e2d

View file

@ -6,10 +6,14 @@ const CarouselSliders = (props) => {
const [activeVideoID, setActiveVideoID] = useState(null);
const players = useRef({});
const activeVid = props.matches.length ? props.matches[0].YouTubeID : "";
useEffect(() => {
setActiveVideoID(activeVid);
if (props.matches.length > 0) {
const firstVideoID = props.matches[0].YouTubeID;
document
.getElementById(`slide-${firstVideoID}`)
.scrollIntoView({ behavior: "smooth" });
setActiveVideoID(firstVideoID);
}
}, [props.matches]);
const onReady = (event, videoId) => {