amp-user-notification
Amp-user-notification adalah untuk menampilkan notifikasi sekali pakai bagi pengguna. Gunakan opsi ini untuk menerapkan kotak dialog untuk memberi tahu pengguna tentang cookie.
1 Codenya
<!doctype html> <html ⚡> <head> <meta charset="utf-8"> <script async src="https://cdn.ampproject.org/v0.js"></script>
2 Caranya
Masukkan script amp-user-notification tepat di bawah pembukaan <head>
<script async custom-element="amp-user-notification" src="https://cdn.ampproject.org/v0/amp-user-notification-0.1.js"></script>
Selain itu, Anda harus mengintegrasikan script amp-analytics tepat di bawah <head>
<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>
3 Ingatlah untuk juga memasukkan CSS, kelas css secara default akan meletakkan elemen amp-user-notification di sudut kiri bawah situs web Anda.
Masukkan gaya CSS berikut, tepat sebelum </head>
<style amp-custom> footer { margin-bottom: 50px; }
amp-user-notification { padding: 8px; background: beige; } </style>
4 Penggunaan penyimpanan lokal
Ketika pengguna menyetujui kebijakan cookie, statusnya disimpan di penyimpanan lokal.
Masukkan kode berikut, tempat Anda ingin notifikasi ditampilkan
<amp-user-notification layout=nodisplay id="amp-user-notification1"> This is an amp-user-notification. It uses local storage to store the dismissed state. <button on="tap:amp-user-notification1.dismiss">I accept</button> </amp-user-notification>
Full struktur kode lengkap
<!doctype html>
<html ⚡>
<head>
<meta charset="utf-8">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-user-notification" src="https://cdn.ampproject.org/v0/amp-user-notification-0.1.js"></script>
<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>
<link rel="canonical" href="http://amphtmlejemplos.blogspot.com/2016/12/como-mostrar-una-notificacion-en-amp.html">
<style amp-custom>
footer {
margin-bottom: 50px;
}
amp-user-notification {
padding: 8px;
background: beige;
}
</style>
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
</head>
<body>
<amp-user-notification layout=nodisplay
id="amp-user-notification1">
This is an amp-user-notification. It uses local storage to store the dismissed state.
<button on="tap:amp-user-notification1.dismiss">I accept</button>
</amp-user-notification>
</body>
</html>