Pen Settings

HTML

CSS

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

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

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.

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

              
                
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="API(ajax)-practice.css">
    <script src="jquery-3.4.1.min.js"></script>
    <title>FunTree</title>
</head>

<body>
     <header id="header">
        <div class="text">
            <h1 id="topic">Travel Around Taichung</h1>
            <small>台中觀光局</small>
        </div>
    </header>
    <section class="section_content">
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <div class="btn" id="btn1" onclick="downloadList('西屯區')">西屯區</div>
                    <div class="btn" id="btn2" onclick="downloadList('北屯區')">北屯區</div>
                    <div class="btn" id="btn3" onclick="downloadList('東區')">東區</div>
                    <div class="btn" id="btn4" onclick="downloadList('北區')">北區</div>
                </div>
                <div class="col-md-12">
                    <ul id="location"></ul>
                </div>
            </div>
        </div>
    </section>
   
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
    <script src="practice.js"></script>
</body>

</html>
              
            
!

CSS

              
                :root {
    --color_white: #f3f3f3;
    --color_yellow: #FFD633;
    --color_black: #222;
    --color_blue_start: #19283D;
    --color_blue_end: #1D678F;
    --color_rain: #4DACFF;
    --color_white_cloud: #f2f9fe;
    --color_grey_cloud: #ccc;
}
* {
    margin: 0;
    padding: 0;
    list-style: none;
    font-family: "微軟正黑體";
}

html,
body {
    height: 100%;
    width: 100%;
}
header{
    width: 100%;
	display: flex;
	justify-content: center;
	-ms-align-items: center;
	align-items: center;
}
header .text {
    width: 100%;
    padding: 350px;
    background-image: url(https://s.newtalk.tw/album/news/173/5bfd195fd38a1.jpg);
    background-attachment: fixed;
    -webkit-background-size: cover;
    background-size: cover;
    background-position: center center;
    display: flex;
    justify-content: center;
    -ms-align-items: center;
    align-items: center;
    -webkit-flex-direction: column;
    -moz-flex-direction: column;
    -ms-flex-direction: column;
    -o-flex-direction: column;
    flex-direction: column;
    
}
@media (max-width: 1280px) {
  #topic {
    text-align: center
  }
}
header h1{
    color: var(--color_white);
    font-size: 4rem;
}
header small{
    color: var(--color_white);
    font-size: 2rem;
}
section.section_content{
    background-color: #fff;
}
section.section_content .col-md-12{
    display: flex;
}
section.section_content .btn{
    width: 5vw;
   
    background-color: var(--color_blue_end);
    border: 1.5px solid var(--color_white);
    border-radius: 8px;
    color: var(--color_white);
    text-align: center;
    line-height: 30px;
    letter-spacing: 5px;
    font-weight: 900 ;
    flex:1;
    margin: 3vw;
    opacity: 0.7;
    transition: 0.7s;
}
section.section_content .btn:hover{
    opacity: 1

}
              
            
!

JS

              
                var dataurl = "https://datacenter.taichung.gov.tw/swagger/OpenData/c60986c5-03fb-49b9-b24f-6656e1de02aa"

var imgurl = "http://taichung-mgmt.csii.com.tw"

var items = []
const replacer = (match, group1, group2, group3, group4, group5) => {
    // console.log(`<img ${group1} ${group2} src="${!~group4.indexOf(imgurl) ? imgurl+group4 : group4}"${group5}`)
    return ` ${group1} ${group2} src="${!~group4.indexOf(imgurl) ? imgurl+group4 : group4}" ${group5}`
}
function downloadList(area) {
    $.ajax({

        url: dataurl,
        success: function(res) {
            var item;
            res
              .filter(items => {
                if (items.鄉鎮市區 == area) return items
              })
              .forEach(data => {
                item = `
                  <li>
                    <h2>${data.名稱}</h2>
                    ${data.介紹.split("<img").map(el => el.replace(/\ (alt=".+") (id=".+") (src="(.+)") (style=".+") /, replacer)).join("<br /><img")}
                  </li>
                `
                $('ul#location').append(item)
              })
            /*for (i = 0; res.length > i; i++) {
                console.log(res)
                items = res
                var area = items[i].鄉鎮市區
                if (area == "西屯區") {

                    item = ` 

                  <li>
                    <h3>${items[i].名稱}</h3>
                    ${items[i].介紹.split("\>").map(el => el.replace(/\<img (alt=".+") (id=".+") (src="(.+)") (style=".+") /, replacer)).join("/>")}
                    

                  </li>

				`

                    $('ul#location').append(item)
                }

            }*/

        }
    })
}



              
            
!
999px

Console