Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Commit

Permalink
Scroll GlassCase to center on render
Browse files Browse the repository at this point in the history
The GlassCase element was always initially centered before commit cb12ae8.

Scroll the element to the center on render to preserve the original look, while allowing all child elements to be seen.
  • Loading branch information
clabinger authored Jul 7, 2021
1 parent cb12ae8 commit d408d33
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/components/sections/Families/GlassCase.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactElement } from "react";
import React, { ReactElement, useEffect } from "react";
import GlassCaseCard, {
GlassCaseCardProps,
} from "src/components/cards/GlassCaseCard";
Expand All @@ -16,9 +16,20 @@ export default function GlassCase(): ReactElement {
{ name: "Beautiful", image: Scenery },
{ name: "Fun", image: Game },
];

const scroller = React.createRef();
const scrollToCenter = () => {
const element = scroller.current;
element.scrollLeft = (element.scrollWidth - element.offsetWidth) / 2;
}

useEffect(() => {
scrollToCenter();
});

return (
<section className="d-flex blue-200-bg flex-column align-items-center py-5">
<div className="d-flex flex-column justify-content-center text-center px-3">
<div className="d-flex flex-column justify-content-center text-center px-3" ref={scroller}>
<span className="dark p2 font-weight-bold">
Always stay close, no matter the distance.
</span>
Expand Down

0 comments on commit d408d33

Please sign in to comment.