A polyfill for the View Transitions API.
The polyfill is available on NPM.
View some demos showing example transitions.
Install the polyfill in your project from NPM:
npm install view-transitions-polyfill
Import the module into your site.
Inside a script:
import 'view-transitions-polyfill';
Or from the HTML:
<script type="module">
import 'view-transitions-polyfill';
</script>
You can use the polyfill with Astro view transitions by importing the script in the document as you would normally. For example, within a component:
<script src="https://github.com/demarketed/view-transitions-polyfill/raw/main/view-transitions-polyfill"></script>
According to data from Can I use, the polyfill should be fully supported on:
This is because the polyfill currently requires the browser to support these notable features:
Build the polyfill to dist
:
npm run build
To test the polyfill, you can run Web Platform Tests. You need to set up your system before running tests.
Run the tests with:
npm run test
This will generate report files in test/report
.
The polyfill only loads its functions into the browser if it does not already natively support the View Transitions API. You can run the tests with a version of the polyfill that avoids this check with:
npm run test-always-polyfill
You can view the tests' web pages in your browser with:
npm run test-debug