<amp-animation id="snackbarSlideIn" layout="nodisplay">
<script type="application/json">
{
"animations": [{
"duration": 300,
"easing": "ease-out",
"iterations": "1",
"selector": ".Snackbar",
"keyframes": [{
"transform": "translateY(100%)",
"opacity": 0
},
{
"transform": "translateY(0)",
"opacity": 1
}
]
},
{
"duration": 300,
"delay": "10s",
"fill": "forwards",
"easing": "ease-in",
"iterations": "1",
"selector": ".Snackbar",
"keyframes": [{
"transform": "translateY(0)",
"opacity": 1
},
{
"transform": "translateY(100%)",
"opacity": 0
}
]
}
]
}
</script>
</amp-animation>
<div submit-error>
<template type="amp-mustache">
<div class="Snackbar AMPSnackbar ">
{{message}}
</div>
</template>
</div>
<amp-animation id="snackbarSlideIn" layout="nodisplay">
<script type="application/json">
{
"animations": [{
"duration": 300,
"easing": "ease-out",
"iterations": "1",
"selector": ".Snackbar",
"keyframes": [
{
"transform": "translateY(100%)",
"opacity": 0
},
{
"transform": "translateY(0)",
"opacity": 1
}
]
},
{
"duration": 300,
"delay": "10s",
"fill": "forwards",
"easing": "ease-in",
"iterations": "1",
"selector": ".Snackbar",
"keyframes": [
{
"transform": "translateY(0)",
"opacity": 1
},
{
"transform": "translateY(100%)",
"opacity": 0
}
]
}]
}
</script>
</amp-animation>
<div submit-error>
<template type="amp-mustache">
<div class="Snackbar AMPSnackbar {{modifier}}">
\{{message}}
</div>
</template>
</div>
{
"modifier": null
}
.AMPSnackbar {
@include ZIndex("Snackbar");
position: fixed;
right: 0;
bottom: 0;
left: 0;
max-width: 34rem;
margin: 0 auto;
}
AMPSnackbar is a combination of amp-mustache
and amp-animation
. On an amp-form
, you can
trigger a Snackbar to appear by setting on="submit-error:snackbarSlideIn.restart"
. It will
render the message
field provided by the JSON response from the XMLHttpRequest.
<script async custom-element="amp-animation" src="https://cdn.ampproject.org/v0/amp-animation-0.1.js"></script>
<script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
<script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.1.js"></script>
A working example may be found under Templates > AMPDemoForm.
amp-form
element.message
field.AMPSnackbar is rendered into a div
with role="alert"
and an aria-labeledby
attribute that
reads the message contents to a screenreader user.