-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,983 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../src/assets/chamber.png |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../src/assets/crossing.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../src/assets/shaft.png |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../src/assets/signal.png |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
title: "Pseudo-Smooth-Scrolling" | ||
description: "Instant scrolling on a page with view transition might lead to an unexpected smooth-scrolling effect. " | ||
--- | ||
|
||
Pseudo-smooth-scrolling is an effect that looks like smooth-scrolling, but in fact is the result of the browser’s default morph animation. It happens when a navigation involves instant scrolling and tall transitions groups. | ||
|
||
Take a look at the image below, showing an abstract website layout with a light blue header, a blue navigation panel, and a light yellow content area. The content area has a `view-transition-name` applied. If you scroll down and then navigate to another page, you might notice something strange: while the scrollbar jumps instantly, the content scrolls smoothly. What's going on here? | ||
|
||
|
||
<svg width="300px" height="150px" viewBox="0 0 300 150" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> | ||
|
||
<rect fill="none" stroke="#aaa" x="0" y="0" width="300" height="150"></rect> | ||
<rect fill="lightblue" stroke="#aaa" x="0" y="0" width="300" height="30"></rect> | ||
<rect fill="steelblue" stroke="#aaa" x="0" y="30" width="70" height="120"></rect> | ||
<rect fill="gray" stroke="#aaa" x="290" y="30" width="10" height="120"></rect> | ||
<rect fill="white" stroke="#aaa" x="290" y="100" width="10" height="30"></rect> | ||
<rect fill="lightyellow" stroke="#aaa" x="70" y="30" width="220" height="120"></rect> | ||
</svg> | ||
|
||
Only part of the content element is visible at a time, as it's much taller than the screen. For simplicity, let's assume the content element is the same size on both the old and new pages. However, different sections of it are displayed. On the old page, the purple section at the bottom is visible. | ||
<svg width="300px" height="250px" viewBox="0 -100 300 250" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> | ||
|
||
<rect fill="none" stroke="#aaa" x="0" y="0" width="300" height="150"></rect> | ||
<rect fill="lightblue" stroke="#aaa" x="0" y="0" width="300" height="30"></rect> | ||
<rect fill="steelblue" stroke="#aaa" x="0" y="30" width="70" height="120"></rect> | ||
<rect fill="gray" stroke="#aaa" x="290" y="30" width="10" height="120"></rect> | ||
<rect fill="white" stroke="#aaa" x="290" y="100" width="10" height="30"></rect> | ||
<rect fill="lightyellow" stroke="#aaa" x="70" y="-100" width="220" height="250"></rect> | ||
<rect fill="none" stroke="darkslateblue" stroke-width="3" x="70" y="32" width="220" height="116"></rect> | ||
</svg> | ||
|
||
On the new page, the top part of the content element is visible, which is the dark green section. | ||
|
||
When you select the new page from the navigation panel, the scrollbar instantly jumps to the top, and the view transition kicks in. Through the default group animation applied to the content element, the browser initially shows the purple-bordered section, then smoothly transitions to the green-bordered area. During this process, it cross-fades between the old and new content. | ||
|
||
<svg width="300px" height="280px" viewBox="0 0 300 280" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> | ||
|
||
<rect fill="none" stroke="#aaa" x="0" y="0" width="300" height="150"></rect> | ||
<rect fill="lightblue" stroke="#aaa" x="0" y="0" width="300" height="30"></rect> | ||
<rect fill="steelblue" stroke="#aaa" x="0" y="30" width="70" height="120"></rect> | ||
<rect fill="gray" stroke="#aaa" x="290" y="30" width="10" height="120"></rect> | ||
<rect fill="white" stroke="#aaa" x="290" y="30" width="10" height="30"></rect> | ||
<rect fill="lightyellow" stroke="#aaa" x="70" y="30" width="220" height="250"></rect> | ||
<rect fill="none" stroke="darkolivegreen" stroke-width="3" x="70" y="32" width="220" height="116"></rect> | ||
<rect fill="none" stroke="darkslateblue" stroke-width="3" x="70" y="160" width="220" height="118"></rect> | ||
</svg> | ||
|
||
So, it’s not the scrollbar slider that smoothly moves from the lower to the upper position, but rather the view transition images that slide down through the viewport. | ||
|
||
## Interactive Demo | ||
[Explore an interactive demo of the effect](/shaft-demo/1/) | ||
|
||
|
||
|
||
## How to Avoid? | ||
|
||
The pseudo-smooth-scrolling effect can be quite appealing if the pages are not too lengthy and you intend to use it deliberately. However, it might also occur unintentionally, especially if you specifically want to avoid smooth scrolling on your pages. | ||
There are two ways to avoid the effect. | ||
|
||
### Just Animate the Root | ||
The pseudo-smooth-scrolling effect only occurs when the `view-transition-name` is applied to an HTML element other than the top-level `<html>` element. The View Transition API [treats the `:root` element differently](https://drafts.csswg.org/css-view-transitions-1/#capture-the-image). The old and new images of the document element are always constrained to the size of the viewport, meaning the default group animation doesn’t transform the position and no scrolling happens at all. | ||
|
||
If possible, resist the temptation to apply a view transition name to large content elements. Instead, use the `root` transition group on the `<html>` element to achieve the desired effect. If you fear that your root group now obscures header, footer, and navbar, you can always assign view transition names to those elements, allowing them to enter the view transition layer and [cover portions of the root images](/basics/pseudos/#rendering-pseudo-elements) as needed. | ||
|
||
### Make Use of the Cam-Shaft | ||
|
||
|
||
|
||
If using the root transition group doesn't meet your design objectives, you can turn to the [`@vtbag/cam-shaft`](/tools/cam-shaft/) script to adjust the images into their proper positions, compensating for the scroll delta. This approach eliminates sliding viewports and the pseudo-smooth-scroll effect. Just identify the transition groups that need adjustments, and let the script take care of the rest. | ||
|
||
<style>{` | ||
svg { | ||
margin: 0 auto; | ||
} | ||
`}</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
--- | ||
title: The Cam-Shaft | ||
description: "Bump your view transition images into position to avoid that unexpected pseudo-smooth-scrolling." | ||
--- | ||
import { Steps } from "@astrojs/starlight/components"; | ||
|
||
<div style="display:flex"> | ||
<div id="logo" style="flex:1; margin: 3ex"> | ||
![The Cam-shaft](../../../assets/shaft.png) | ||
</div><div style="flex:3"> | ||
|
||
Bump your view transition images into position to avoid that unexpected pseudo-smooth-scrolling. | ||
|
||
The Cam-Shaft is about an issue we already resolved for Astro's ViewTransitions (see [here](https://events-3bg.pages.dev/jotter/starlight/inner-workings/transitions/#the-pseudo-scrolling-main-area) and [here](https://events-3bg.pages.dev/library/PageOffset/)), but it still requires support for browser-native cross-document view transitions. | ||
|
||
</div> | ||
</div> | ||
<style>{` | ||
#logo img { | ||
view-transition-name: logo; | ||
mask-image: radial-gradient( | ||
ellipse at center, | ||
white 35%, | ||
transparent 71% | ||
); | ||
} | ||
`}</style> | ||
|
||
|
||
## PREREQUISITE | ||
|
||
:::tip[View Transition API] | ||
The Camshaft is designed to address an issue with browser-native cross-document view transitions. In browsers that haven't implemented the API yet, it simply does nothing, as there's no problem to solve. | ||
::: | ||
|
||
|
||
## What is it? | ||
|
||
This tools is intended to avoid the [pseudo-smooth-scroll effect](/tips/pseudo-smooth-scrolling/). | ||
|
||
See the [interactive demo of the effect](/shaft-demo/1/) and the [interactive demo of the solution using the cam-shaft](/shaft-demo2/1/). | ||
|
||
|
||
## Installation | ||
:::tip | ||
If you want to use the Cam-Shaft with an Astro project, see [astro-vtbot](https://events-3bg.pages.dev/library/CamShaft/) for reusable components you can easily use in your project. | ||
::: | ||
|
||
To use the Cam-Shaft, you can install the npm package in your project. Alternatively you can load the script from one of the global content delivery networks that provide npm packages. | ||
|
||
import { Tabs, TabItem } from "@astrojs/starlight/components"; | ||
|
||
<Tabs> | ||
<TabItem label="Using the npm package" icon="seti:npm"> | ||
<Steps> | ||
1. Install `@vtbag/cam-shaft@latest` from npm. | ||
2. In your project, add `@vtbag/cam-shaft/index.js` as an inline script at the beginning of the `<head>` element on all pages of your site. | ||
</Steps> | ||
|
||
Details depend on your project setup and the frameworks used, but it can be as simple as: | ||
|
||
```jsx | ||
import shaft from "@vtbag/cam-shaft?url"; | ||
<html> | ||
<head> | ||
<script src={shaft} /> | ||
... | ||
</head> | ||
... | ||
</html>; | ||
``` | ||
</TabItem> | ||
<TabItem label="Loading the script from a CDN" icon="cloudflare"> | ||
|
||
You can load the script from CDNs such as jsdelivr.net or unpkg.com. Place the script inline at the beginning of the `<head>` element on all pages where you need avoid pseudo-smooth-scrolling. | ||
|
||
Using `jsdeliver.net`: | ||
|
||
```html | ||
<html> | ||
<head> | ||
<script src="https://cdn.jsdelivr.net/npm/@vtbag/cam-shaft" /> | ||
... | ||
</head> | ||
... | ||
</html> | ||
``` | ||
or alternatively using `unpkg.com`: | ||
```html | ||
<html> | ||
<head> | ||
<script src="https://unpkg.com/@vtbag/cam-shaft" /> | ||
... | ||
</head> | ||
... | ||
</html> | ||
``` | ||
</TabItem> | ||
</Tabs> | ||
## Configuration and Usage | ||
The Cam-Shaft script needs to know which view transition name's images it should bump and nudge. By default, it assumes it should handle `::view-transition-group(main)`. | ||
If you need to target a different view transition name, you can use the `data-view-transition-names` attribute in the script tag. For example, the following will instruct the script to handle images for `::view-transition-group(content)`: | ||
```html | ||
<script src=... data-view-transition-names="content"/> | ||
``` | ||
As you may have guessed from the plural form, you can specify multiple view transition names by separating them with spaces, allowing the script to manage several groups. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<svg width="300" height="300" viewBox="0 0 300 300" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> | ||
|
||
|
||
</svg> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.