Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="loading">載入中</div>
<div id="show-data"></div>

              
            
!

CSS

              
                
              
            
!

JS

              
                $(document).ready(function() {
  $.ajax({
    type: "GET", // 採用 GET 形式取得資料
    url:
      "https://cors-anywhere.herokuapp.com/https://mnya.tw/cc/wp-json/wordpress-popular-posts/v1/popular-posts/?post_type=post&range=last24hours&limit=2", // 取得資料的 API 位址
    async: true, // 非同步取得 JSON 資料
    dataType: "json", // 資料格式
    success: function(data) {
      // 成功取得資料執行的程式區塊
      html = ""; // 存放 HTML 用
      for (var i = 0, len = data.length; i < len; i++) {
        // 取得每筆資料

        //-- 取得資料區 --//
        html_link = data[i].link; // 取得文章連結
        html_title = data[i].title.rendered; // 取得文章標題
        html_featured_img = data[i].jetpack_featured_media_url; // 取得縮圖
        html_date = data[i].date.substring(0, 10); // 取得發表日期(時間已被去除)
        html_pageviews = data[i].pageviews; // 取得瀏覽量
        html_excerpt = data[i].excerpt.rendered.substring(0, 60); // 取得文章摘要(限制在 60 字元以內)

        //-- 將資料與 HTML 標籤結合區 --//
        html +=
          "<a href='" +
          html_link +
          "'><div><img src='" +
          html_featured_img +
          "' alt=''></div><h2>" +
          html_title +
          "</h2></a><div><i>📝 " +
          html_date +
          " 📊 " +
          html_pageviews +
          "</i><br>" +
          html_excerpt +
          "</div>";

        //-- Console 偵錯區 --//
        console.log(data[i]); // 印出所有取得資料至 Console
      }
      //-- HTML <body> 寫入區 --//
      $("#show-data").append(html); // 將 HTML 塞入 <div id="show-data"></div>
      $("#loading").hide(); // 隱藏載入中字樣
    }
  });
});

              
            
!
999px

Console