Controls track scroll
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { For, createSignal } from 'solid-js';
|
import { For, createSignal } from 'solid-js';
|
||||||
|
import { createEffect } from 'solid-js';
|
||||||
|
|
||||||
import { useStore } from '../store/index';
|
import { useStore } from '../store/index';
|
||||||
import styles from './Controls.module.css';
|
import styles from './Controls.module.css';
|
||||||
@@ -7,39 +8,46 @@ import gridIcon from '../assets/icons/grid.svg'
|
|||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const [store] = useStore();
|
const [store] = useStore();
|
||||||
const [selected, setSelected] = createSignal(0);
|
const [selected, setSelected] = createSignal('home');
|
||||||
const [blobby, setBlobby] = createSignal([0]);
|
const [blobby, setBlobby] = createSignal(['home']);
|
||||||
const controls = [
|
const controls = [
|
||||||
{ name: 'home', icon: homeIcon },
|
{ name: 'home', icon: homeIcon },
|
||||||
{ name: 'projects', icon: gridIcon },
|
{ name: 'projects', icon: gridIcon },
|
||||||
{ name: 'whatever', icon: homeIcon },
|
{ name: 'whatever', icon: homeIcon },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const selectChapter = (chapterName: string) => {
|
||||||
|
if (chapterName !== selected()) {
|
||||||
|
setSelected(chapterName)
|
||||||
|
setBlobby(b => [chapterName, ...b])
|
||||||
|
setTimeout(() => {
|
||||||
|
setBlobby(b => [chapterName])
|
||||||
|
}, 500)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
createEffect(() => {
|
||||||
|
selectChapter(store.visibleChapter());
|
||||||
|
return store.visibleChapter();
|
||||||
|
}, 'home');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div class={styles.Controls}>
|
<div class={styles.Controls}>
|
||||||
<div class={styles.gooWrapper}>
|
<div class={styles.gooWrapper}>
|
||||||
<For each={controls}>{(control, i) =>
|
<For each={controls}>{(control) =>
|
||||||
<div
|
<div
|
||||||
class={styles.blob}
|
class={styles.blob}
|
||||||
classList={{
|
classList={{
|
||||||
[styles.selected]: blobby().includes(i())
|
[styles.selected]: blobby().includes(control.name)
|
||||||
}}
|
}}
|
||||||
></div>
|
></div>
|
||||||
}</For>
|
}</For>
|
||||||
</div>
|
</div>
|
||||||
<div class={styles.controlsWrapper}>
|
<div class={styles.controlsWrapper}>
|
||||||
<For each={controls}>{(control, i) =>
|
<For each={controls}>{(control) =>
|
||||||
<div
|
<div
|
||||||
onClick={() => {
|
onClick={() => selectChapter(control.name)}
|
||||||
if (i() !== selected()) {
|
|
||||||
setSelected(i())
|
|
||||||
setBlobby(b => [i(), ...b])
|
|
||||||
setTimeout(() => {
|
|
||||||
setBlobby(b => [i()])
|
|
||||||
}, 500)
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
class={styles.control}
|
class={styles.control}
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
|
|||||||
@@ -6,17 +6,16 @@ import styles from './Hero.module.css';
|
|||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const [t] = useI18n();
|
const [t] = useI18n();
|
||||||
const [add] = createViewportObserver();
|
const [observer] = createViewportObserver({threshold: 0.9});
|
||||||
const [, { setVisibleChapter }] = useStore();
|
const [, { setVisibleChapter }] = useStore();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header
|
<header
|
||||||
ref={el => {
|
use:observer={(event) => {
|
||||||
add(el, (event) => {
|
if (event.isIntersecting) {
|
||||||
console.log(event.isIntersecting);
|
|
||||||
setVisibleChapter('home');
|
setVisibleChapter('home');
|
||||||
});
|
}}
|
||||||
}}
|
}
|
||||||
class={styles.Hero}
|
class={styles.Hero}
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
.Projects {
|
.Projects {
|
||||||
|
height: 101vh;
|
||||||
padding: 32px;
|
padding: 32px;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|||||||
@@ -5,16 +5,15 @@ import styles from './Projects.module.css';
|
|||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const [, { setVisibleChapter }] = useStore();
|
const [, { setVisibleChapter }] = useStore();
|
||||||
const [add] = createViewportObserver();
|
const [observer] = createViewportObserver({threshold: 0.9});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={el => {
|
use:observer={(event) => {
|
||||||
add(el, (event) => {
|
if (event.isIntersecting) {
|
||||||
console.log(event.isIntersecting);
|
|
||||||
setVisibleChapter('projects');
|
setVisibleChapter('projects');
|
||||||
});
|
}}
|
||||||
}}
|
}
|
||||||
class={styles.Projects}
|
class={styles.Projects}
|
||||||
>
|
>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user