Google-amp-user-notification

提供:Dev Guides
移動先:案内検索

Google AMP-ユーザー通知

Google amp-user-notificationは、ユーザーに非表示のダイアログボックスメッセージを表示するために使用されます。 これを使用して、ページ上のCookieについてユーザーに通知できます。

amp-user-notificationを使用するには、ページに次のスクリプトを追加する必要があります-

<script async custom-element = "amp-user-notification"
   src = "https://cdn.ampproject.org/v0/amp-user-notification-0.1.js">
</script>

Amp-user-notificationタグの形式-

<amp-user-notification id = "my-notification" layout = "nodisplay">
   <div>Example of amp-user-notification.
      <button on = "tap:my-notification.dismiss">I accept
      </button>
   </div>
</amp-user-notification>

実際の例を使用してamp-user-notificationを理解しましょう-

<!doctype html>
<html amp lang = "en">
   <head>
      <meta charset = "utf-8">
      <script async src = "https://cdn.ampproject.org/v0.js"></script>
      <title>Google AMP - Amp Selector</title>
      <link rel = "canonical" href = " http://example.ampproject.org/article-metadatal">
      <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>

      <script async custom-element = "amp-user-notification"
         src = "https://cdn.ampproject.org/v0/amp-user-notification-0.1.js">
      </script>

      <style amp-custom>
         div {
            font-size: 15px;
            background-color : #ccc;
            padding: 10px 10px;
            border-radius: 2px;
         }
         button{
            background-color: #ACAD5C;
            color: white;
            cursor: pointer;
            float: right;
         }
      </style>
   </head>
   <body>
      <h3>Google AMP - Amp User Notification</h3>
      <amp-user-notification
         id = "my-notification"
         layout = "nodisplay">
         <div>Example of amp-user-notification.
            <button on = "tap:my-notification.dismiss">I accept
            </button>
         </div>
      </amp-user-notification>
   </body>
</html>

出力

上記の作業例のコードの出力は以下のとおりです-

Amp Font User Notification

ユーザーがボタンをクリックすると、通知は閉じられます。 一度削除すると、ページをリロードしても通知は表示されません。

ユーザー通知のデータはブラウザーのlocalStorageに保存されます。localstorageがクリアされてページが更新されると、通知を再度表示できます。 ブラウザコンソールで* localStorage.clear()*を使用して同じことを試すことができます。

*dismiss* アクションを使用すると、次のようにボタンのアクションを使用して、通知を却下できます。
<button on = "tap:my-notification.dismiss">
   I accept
</button>

ユーザーがボタンをタップすると、通知は消えます。