Skip to content

Commit

Permalink
click to go to tween
Browse files Browse the repository at this point in the history
  • Loading branch information
julianbenegas committed Oct 10, 2023
1 parent 25c164d commit cc39966
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions scrollytelling/src/components/debugger/visualizer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ const Tween = ({
const [isHovering, setIsHovering] = useState(false);
const [active, setActive] = useState(false);

const data = tween.data;

// Highlight tween target element on hover
useEffect(() => {
if (isHovering) {
Expand Down Expand Up @@ -104,20 +102,16 @@ const Tween = ({
onMouseEnter={() => setIsHovering(true)}
onMouseLeave={() => setIsHovering(false)}
onClick={() => {
// todo scroll to regular tweens
// should we have a label for every timeline? or is there an easier way to do this?

const st = root.tween?.scrollTrigger;
if (!st) return;

if (data.type === "waypoint") {
// scroll to label
const foundLabel = root.tween?.labels[data.label];
if (foundLabel) {
const targetPx = st.labelToScroll(data.label);
window.scrollTo({ top: targetPx + 0, behavior: "smooth" });
}
}
const start = st.start;
const end = st.end;
const scroll = start + (end - start) * (tween._start / 100);

console.log({ start, end, tweenStart: tween._start });

window.scrollTo({ top: scroll, behavior: "smooth" });
}}
>
{targetString}
Expand All @@ -127,6 +121,7 @@ const Tween = ({

const Waypoint = ({
tween,
root,
}: {
tween: VisualizerItem;
root: VisualizerRoot;
Expand Down Expand Up @@ -155,6 +150,19 @@ const Waypoint = ({
"--start-offset-percentage": tween._start + "%",
}}
className={s["waypoint"]}
onClick={() => {
const st = root.tween?.scrollTrigger;
if (!st) return;

if (tween.data.type === "waypoint") {
// scroll to label
const foundLabel = root.tween?.labels[tween.data.label];
if (foundLabel) {
const targetPx = st.labelToScroll(tween.data.label);
window.scrollTo({ top: targetPx + 0, behavior: "smooth" });
}
}
}}
>
<span
className={clsx(
Expand Down

1 comment on commit cc39966

@vercel
Copy link

@vercel vercel bot commented on cc39966 Oct 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.