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

              
                <header>
        <h1>台灣各縣市當前氣象監測</h1>

    </header>
    <div id="main" class="container">
        <form>
            <select class="selectLocation" name="YourLocation">
                <option value="">---請選擇地點----</option>
            </select>
        </form>
        <!-- <div class="weatherBox">
            <div class="location"></div>
            <div class="time"></div>
            <div class="status"></div>
            <div class="temperature">
        </div> -->
        <div class="weatherBoxContainer"></div>

    </div>
    <section class="background">
        <div class="headerCircle" id="circle01"></div>
        <div class="headerCircle" id="circle02"></div>
    </section>
              
            
!

CSS

              
                /* All */
*{ padding: 0; margin: 0; }
html, body{ box-sizing: border-box; height: 100%;}
h1 { background: -webkit-linear-gradient( #4895cf, #3d7bb2, #0065a6, #4c88bd,#a4c0d5);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent; 
    letter-spacing: 1rem;}
h2 { margin: 2rem 0;}
h4 { font-weight: 200; }
body { font-family:  'Roboto', 'Noto Sans TC', sans-serif; position: relative;
height: 100%; width: 100%;
}
/* header */
header {  text-align: center; padding: 60px 0; box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.534);
    
  }
.container { margin: 5% auto; min-height: 100%; padding:0 3%;}
.selectLocation  { height: 2rem; width:30%; display: block;margin: 2rem auto;
    border: 2px solid #fccb90; border-radius: 10px;
    color:#9b621e; font-family:  'Noto Sans TC'; font-size: 1.1rem;
}

/* weather box */
.weatherBox { width: 20%; float: left; margin:1.5% 3% 1.5% 0; padding: 1%;
    box-shadow: 2px 3px 5px rgba(0, 0, 0, 0.342);
    text-align: center; border-radius: 5px; background-color: rgba(255, 255, 255, 0.753);
    }
.location{ font-size: 1.1rem; font-weight: 300; padding: 5px 1.5%;}
/* .card-header a { color: rgb(107, 212, 133); } */
.card-list { list-style: none; font-weight: 100; padding: 0 1.5%}
.card-list li{ padding: 5px; }
/* RWD 手機版 */
@media(max-width:768px){ .weatherBox { width: 28%; }}
@media(max-width:550px){ .weatherBox { width: 45%; }}
@media(max-width:420px){ 
    header { padding: 30px 0; }
    h1 { letter-spacing: 0rem; }
    .weatherBox { width: 95%; text-align: left; margin:1.5% 3% 1.5% 1.5%; }
    .card-header { float: left; width: 37%; position: relative; }
    .card ul { float: left; width: 57%; }
    .card-footer { display: none; }
    .custom-select  { width:50%; }
    .card-header a {position: absolute; }
    .publishTime { display: inline-block; }
    }
/* background */
.background{ background-color:#444;
    height: 100%; width: 100%;position: fixed; top:0; z-index: -1;
    background-image: linear-gradient(120deg, #fccb90 0%, #d57eeb 100%);
}
.headerCircle { position: absolute;background-color: #3d7bb2; 
transform: translate(-50%,-50%); border-radius: 50%; 
background-image: linear-gradient(180deg, #fccb90 0%, #d57eeb 100%);
z-index: 0;}
#circle01 {height: 25vh; width: 25vh; 
left: 10%; top: 30%;
animation: circle01anim 20s linear infinite}
@-webkit-keyframes circle01anim {
  25% {left: 60%; top: 90%;}
  50% {left: 90%; top: 40%;}
  75% {left: 30%; top: 10%;}
  100% {left: 10%; top: 30%;}
}
#circle02 {height: 25vh; width: 25vh; 
    left: 70%; top: 10%;
animation: circle02anim 20s linear infinite}
@-webkit-keyframes circle02anim {
  25% {left: 90%; top: 30%;} 
  50% {left: 10%; top: 50%;}
  75% {left: 40%; top: 90%;} 
  100% {left: 70%; top: 10%;}
}
              
            
!

JS

              
                $(function(){
    $.ajax({
      method: 'GET',
      url: "https://opendata.cwb.gov.tw/api/v1/rest/datastore/F-C0032-001?Authorization=CWB-769F28FD-6CB2-4AA0-AAAF-55E0301D726C",
      type:'json'
      })
      .done(function(response) {
        var datas = response.records.location;
        // 一開始時先全部的縣市顯示
        for (i=0; i<datas.length; i++){
            $('.selectLocation').append(
                `<option value="${datas[i].locationName}">
                    ${datas[i].locationName}
                </option>`
            );
            $('.weatherBoxContainer').append(
                `<div class="weatherBox" id="site${i}">
                    <div class="location"><h3>${datas[i].locationName}</h3></div>
                    <div class="time">${datas[0].weatherElement[0].time[0].startTime+"~"+datas[0].weatherElement[0].time[0].endTime}</div>
                    <div class="status">${datas[0].weatherElement[0].time[0].parameter.parameterName}</div>
                    <div class="temperature">${datas[0].weatherElement[2].time[0].parameter.parameterName+"度"}</div>
                </div>`
            );
        }
        // select城市的時候清單會跟著顯示
        $('.selectLocation').change(function(){
            var selectedLocation = $(this).children("option:selected").val();
            if(selectedLocation!==""){
                var filteredDatas = datas.filter(function(data){
                    return data.locationName===selectedLocation;

                });
            }else{
                filteredDatas=datas;
            }
            var filteredContent="";
            for (i=0; i<filteredDatas.length; i++){
                var tmp= `<div class="weatherBox" id="site${i}">
                    <div class="location"><h3>${filteredDatas[i].locationName}</h3></div>
                    <div class="time">${filteredDatas[0].weatherElement[0].time[0].startTime+"~"+filteredDatas[0].weatherElement[0].time[0].endTime}</div>
                    <div class="status">${filteredDatas[0].weatherElement[0].time[0].parameter.parameterName}</div>
                    <div class="temperature">${filteredDatas[0].weatherElement[2].time[0].parameter.parameterName+"度"}</div>
                </div>`
                filteredContent= filteredContent+tmp
            }
            $('.weatherBoxContainer').html(filteredContent);
            console.log("filteredDatas",filteredDatas);
        })   
    })
})
              
            
!
999px

Console