Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!DOCTYPE html>
<html amp lang="zh-TW">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<script async src="https://cdn.ampproject.org/v0.js"></script>
    <script async custom-element="amp-font" src="https://cdn.ampproject.org/v0/amp-font-0.1.js"></script>
    <script async custom-element="amp-selector" src="https://cdn.ampproject.org/v0/amp-selector-0.1.js"></script>
    <script async custom-element="amp-bind" src="https://cdn.ampproject.org/v0/amp-bind-0.1.js"></script>


<title>amp-bind測試</title>
<!-- 連回自己 -->
<link rel="canonical" href="amp-product-page">
<!-- font css -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<style amp-custom>
  body{
    padding:16px;
  }


/*顏色區塊*/
  .selector-color{
    
  }
  .selector-color ul{
    margin:0;
    padding:0;
    display:flex;
  }
 .selector-color li{
   padding:0;
   margin:6px;
   list-style-type: none;
   font-size:0;
   width:40px;
   height:40px;
   border:3px solid #eeeeee ;
  }
  .selector-color  [option="1001"]{
    background:#D81B60;
  }
 .selector-color  [option="1002"]{
    background:#FFC107;
  }
 .selector-color  [option="1003"]{
    background:#03A9F4;
  }
 .selector-color  [option="1004"]{
    background:#4CAF50;
  }
  #last_price{
    font-size:32px;
    color:red;
  }
  
  .selector-size ul{
    margin:0;
    padding:0;
    display:flex;
  }
   .selector-size li{
   padding:0;
   margin:6px;
   list-style-type: none;
   text-align:center;
   line-height:40px;
   width:40px;
   height:40px;
   border:3px solid #eeeeee ;
  }

  
</style>
<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>
 <!-- 幣別+各產品選擇-價錢等於只有一種 -->
  <!-- selectedProducts和selectedCurrency是變數;selectedProducts將會撈取1001-1004其中一項,預設值設定1001;selectedCurrency會撈取TWD-HKD等幣別,因此預設值設TWD -->
  <amp-state id="product">
    <script type="application/json">
    {
      "selectedProducts": "1001",
       "selectedSizes": "S",
      "selectedCurrency": "TWD",
       "defaultPrice":"1690",
       "currency" :{
           "TWD":{
          "icon":"$",  
          "price":"1690"
             },
         "HKD":{
          "icon":"$",  
          "price":"427"
             },
         "USD":{
          "icon":"$",  
          "price":"55"
             },
          "JPY":{
          "icon":"¥",  
          "price":"5300"
             },
         "THB":{
          "icon":"฿",  
          "price":"1700"
             }
        },
      "1001":{
        "color":"紅色",
          "sizes":{
            "S":"S",
            "M":"M",
            "L":"L"
          }
      },
         "1002":{
        "color":"黃色",
          "sizes":{
            "S":"S",
            "M":"M",
            "L":"L"
          }
      },
         "1003":{
        "color":"藍色",
          "sizes":{
            "S":"S",
            "M":"M",
            "L":"L"
          }
      },
         "1004":{
        "color":"綠色",
          "sizes":{
            "S":"S",
            "M":"M",
            "L":"L"
          }
      }
     }
    </script>
    </amp-state>
   <h2>產品標題  <span  [text]="product[product.selectedProducts].color">紅色</span> <span  [text]="product[product.selectedProducts].sizes[product.selectedSizes]">S</span> 
</h2>
  <p id="last_price">
  <span [text]="product.currency[product.selectedCurrency].icon">$</span>
  <span  [text]="product.currency[product.selectedCurrency].price">1690</span> 
  </p>  
<!-- 選幣別-注意使用select時on="change..." event接續的是value -->
<select on="change:AMP.setState({ product: {selectedCurrency: event.value }})">

  <option value="TWD">台幣</option>
  <option value="HKD">港幣</option>
  <option value="USD">美元</option>
  <option value="JPY">日幣</option>
  <option value="THB">泰銖</option>
</select>  
  
<!-- 選顏色-->
<amp-selector name="color" class="selector-color" layout="container"
          on="select:AMP.setState({ product: {selectedProducts: event.targetOption}})"
         [selected]="product.selectedProducts.color">
          <ul>
            <li option="1001">紅色</li>
            <li option="1002">黃色</li>
            <li option="1003">藍色</li>
            <li option="1004">綠色</li>
          </ul>
        </amp-selector>
<!-- 選尺寸  尺寸仍然要給一個變數selectedSizes,仿造顏色的方式下去寫-->
<amp-selector name="color" class="selector-size" layout="container"
          on="select:AMP.setState({ product: {selectedSizes: event.targetOption}})"
         [selected]="product.selectedSizes.sizes">
          <ul >
            <li option="S">S</li>
            <li option="M">M</li>
            <li option="L">L</li>
          </ul>
        </amp-selector>
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console