Skip to content

Commit

Permalink
Mt/link types (#18)
Browse files Browse the repository at this point in the history
* new link-types script

* wording

* remove console logs

* wording

* Update README.md

* Update README.md
  • Loading branch information
martrapp authored Dec 11, 2024
1 parent 34d6a93 commit 1b450ab
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/gold-oranges-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vtbag/turn-signal': minor
---

link-types: assign view transition types directly to the links that trigger navigation!
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ Check out the [image viewer tech demo](https://vtbag.dev/viewwe-demo/) for a han

Happy animating! 🎉

For details see the [CHANGELOG](https://github.com/vtbag/turn-signal/blob/main/CHANGELOG.md).



<!--{/*and the [documentation](https://vtbag.dev/tools/turn-signal/).*/}-->

### What happened before?

> Transition types and direction attributes are now also determined on the old page!
For details see the [CHANGELOG](https://github.com/vtbag/turn-signal/blob/main/CHANGELOG.md) and the [documentation](https://vtbag.dev/tools/turn-signal/).

## What is it?

Turn-Signal is a lightweight script that enhances *browser-native* *cross-document* **view transitions** by detecting the **direction** of browser **navigation**. It enables developers to create smooth, responsive transitions that adjust based on forward or backward navigation, delivering a more intuitive user experience.
Expand All @@ -41,4 +39,4 @@ The script automatically detects the traversal direction and sets `backward`, `s

If your site has the concept of a _previous_ and _next_ page, the Turn-Signal can automatically generate directional transitions for you.

[See the Turn Signal in action](https://vtbag.dev/signal-demo/bag/) and [see how it can be customized](https://vtbag.dev/tools/turn-signal/).
[See the Turn Signal in action](https://vtbag.dev/signal-demo/bag/) and [see how it can be customized](https://vtbag.dev/tools/turn-signal/).
3 changes: 0 additions & 3 deletions src/link-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ addEventListener('pageswap', (event) => {
if (activation(event).navigationType === 'traverse' && direction(event) === 'backward') return;
if (lastAnchor) {
types = lastAnchor.getAttribute('data-vtbag-link-types') ?? '';
console.log('s-types :>> ', types);
setViewTransitionTypes(types);
}
sessionStorage?.setItem('vtbag-link-types', types.split(/\s*\/\s*/, 1)[0]);
sessionStorage
?.getItem('vtbag-link-types')
?.split(/\s+/)
.forEach((type) => event.viewTransition?.types?.add(type));
console.log('x', ...event.viewTransition?.types);
});

addEventListener('pagereveal', (event) => {
Expand All @@ -37,7 +35,6 @@ addEventListener('pagereveal', (event) => {
types.includes('/') && (types = types.split(/\s*\/\s*/, 2)[1]);
}
types.split(/\s+/).forEach((type) => event.viewTransition?.types?.add(type));
console.log('r-types :>> ', [...event.viewTransition?.types]);
});

export function setViewTransitionTypes(types: string) {
Expand Down

0 comments on commit 1b450ab

Please sign in to comment.