<media-loading-indicator>
The <media-loading-indicator>
component indicates when the media is buffering. By default, this element is hidden and will only be shown when media loading is stalled.
The component will be updated automatically based on media state and the functionality can be configured.
- The
loadingdelay
attribute to have the loading indicator wait the provided amount of milliseconds before showing. - What is being displayed can be configured via the
loading
slot.
Default usage
Section titled Default usageCustomize icons
Section titled Customize iconsYou can modify the contents of the <media-loading-indicator>
component using slots.
This is useful if you’d like to use your own custom loading indicator instead of the default one provided by media-chrome.
Here is an example with custom SVGs:
Configuring the loading indicator
Section titled Configuring the loading indicatorChanging the loading delay
Section titled Changing the loading delayIt’s possible to change how long the loading indicator waits before showing itself when the media state changes to loading.
There are 3 ways of changing the delay: an attribute, a property, or a CSS variable. All values are in milliseconds.
Via an attribute
Section titled Via an attribute<media-loading-indicator loadingdelay=1000></media-loading-indicator>
Via a property
Section titled Via a propertyconst loadingIndicator = document.querySelector('media-loading-indicator');
loadingIndicator.loadingDelay = 1000;
Via a CSS Variable
Section titled Via a CSS Variablemedia-loading-indicator {
--media-loading-indicator-transition-delay: 1000ms;
}
Making the loading indicator always be visible
Section titled Making the loading indicator always be visibleIt’s possible to keep the loading indicator always visible via a CSS variable.
media-loading-indicator {
--media-loading-indicator-opacity: 1;
}
See the Customize Icons section above for this in action.
Styling with attributes
Section titled Styling with attributesThe <media-loading-indicator>
will be updated with media state attributes depending on the media and playback states.
You can use these attributes to apply custom styles to your <media-loading-indicator>
. For example, if the media is loading but you want the indicator to be semi-transparent, you can change the opacity like so:
media-loading-indicator[medialoading]:not([mediapaused]) {
--media-loading-indicator-opacity: 0.75;
}
Reference
Section titled ReferenceSlots
Section titled SlotsName | Description |
---|---|
loading |
The element shown for when the media is in a buffering state. |
Attributes
Section titled AttributesName | Type | Description |
---|---|---|
loadingdelay |
string |
Set the delay in ms before the loading animation is shown. |
mediacontroller |
string |
The element `id` of the media controller to connect to (if not nested within). |
Media UI Attributes
Section titled Media UI Attributes
The media UI attributes will be set automatically by the controller if they are
connected via nesting or the mediacontroller
attribute.
Only set these attributes manually if you know what you're doing.
Name | Type | Description |
---|---|---|
mediapaused |
boolean |
Present if the media is paused. |
medialoading |
boolean |
Present if the media is loading. |
CSS Variables
Section titled CSS VariablesName | Default | Description |
---|---|---|
--media-primary-color |
rgb(238 238 238) |
Default color of text and icon. |
--media-icon-color |
var(--media-primary-color, rgb(238 238 238)) |
fill color of button icon. |
--media-control-display |
var(--media-loading-indicator-display, inline-block) |
display property of control. |
--media-loading-indicator-display |
inline-block |
display property of loading indicator. |
--media-loading-indicator-opacity |
0 |
opacity property of loading indicator. Set to 1 to force it to be visible. |
--media-loading-indicator-transition-delay |
500ms |
transition-delay property of loading indicator. Make sure to include units. |
--media-loading-icon-width |
100px |
width of loading icon. |
--media-loading-icon-height |
height of loading icon. |