A Web Component to surface an audio or video's duration as a CSS Custom Property.
<script type="module" src="duration-property.js"></script>
<duration-property>
<audio controls src="https://darn.es/sounds/daviddarnes.m4a"></audio>
</duration-property>
This Web Component allows you to:
- Surface the duration of an audio or video elements source duration as a CSS Custom Property (
--duration
) - Update the
--duration
custom property if the duration of the source changes
You have a few options (choose one of these):
- Install via npm:
npm install @daviddarnes/duration-property
- Download the source manually from GitHub into your project.
- Skip this step and use the script directly via a 3rd party CDN (not recommended for production use)
Make sure you include the <script>
in your project (choose one of these):
<!-- Host yourself -->
<script type="module" src="duration-property.js"></script>
<!-- 3rd party CDN, not recommended for production use -->
<script type="module" src="https://www.unpkg.com/@daviddarnes/[email protected]/duration-property.js"></script>
<!-- 3rd party CDN, not recommended for production use -->
<script type="module" src="https://esm.sh/@daviddarnes/[email protected]"></script>
With thanks to the following people:
- Zach Leatherman for inspiring this Web Component repo template