cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

            
              <head>
  <link href="https://fonts.googleapis.com/css?family=Lora" rel="stylesheet">
</head>
<body>
<!--div for sunny-->
<div id="sunnyDay">
  <div class="container weatherBox" >
     <!--<img class="sunny" src= "https://st3.depositphotos.com/2488555/14072/i/1600/depositphotos_140724994-stock-photo-watercolor-green-background-with-tropical.jpg" alt="forest">-->
    <h2 class="center temp" title = "click to change the unit"></h2>
    <canvas id="icon1" class="center icon"></canvas>
    <div id="location1" class="center location"> Your location </div>
    <div id="location2" class="description center">Weather description</div>
  </div>
</div>
</body>
   
            
          
!
            
              body{
 background-color:none;
 font-family: 'Lora', serif;
}

h2{
  color:#c12c60;
}

.temp{
  margin-top:-25%;
  font-size:2.5em;
}


a {
 color:#c12c60;
}

a:hover{
  color:white;
  text-decoration: none;
}

.icon{
  display:flex;
  flex-direction:center;
  margin-top:-5%;
  max-width:50%;

  }

.location{
  margin-top:25%;
  color: #a5276d;
  font-size:25px;
  max-height:100%;
  max-width:100%;
  overflow:auto;
}

.description{
  max-height:100%;
  margin:10% 0% 10% 0%;
  color: #bf1875;
  font-size:25px;
}

.container {
  position: relative;
}

.center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.weatherBox{
  margin:20% auto;
  padding:35%;
  border: 5px solid white; 
  border-radius: 50%;
  background-color:#ffddf0;
  /*opacity: 0.9;
  /*filter: alpha(opacity=20);
  
   /* For IE8 and earlier */
}

/*.sunny,.cloudy,.rainy{
    max-width: 100%;
    height: auto;
    opacity: 0.3;
    filter: alpha(opacity=50); /* For IE8 and earlier */
   /* display:none;*/
}

/*h2 {
  user-select: none;
}*/




            
          
!
            
              var lon, lat;
//var api = "https://api.darksky.net/forecast/";
//var apiKey ="328d1f1b25c1a27c29b58d20b0ab29d5";
//Test geolocation and get current position
$(document).ready(function()
{
    if (navigator.geolocation) 
    {
      navigator.geolocation.getCurrentPosition(function(position) 
      {
      var lon = position.coords.longitude;
      var lat = position.coords.latitude;
      getWeather(lon, lat);
      }          )//getposition;
    } 
    else 
    {
    console.log("Geolocation is not supported by your browser");
    }
}               );

function getWeather(lon, lat)
{
  $.getJSON(
    "https://cors-anywhere.herokuapp.com/https://api.darksky.net/forecast/328d1f1b25c1a27c29b58d20b0ab29d5/" +
      lat +
      "," +
      lon,
    function(result) 
    {
      $(".temp").html(Math.round(result.currently.temperature) + "<a href=#>&deg;F</a>");
      $("#location1").html(result.timezone + " ");
 
 // $("#location1").html(result.name + ", " + result.sys.country);
      $("#location2").html(result.currently.summary);
      //skycons
var iconRequest = result.currently.icon;
var icons = new Skycons({"color": "#c12c60"});
var iconList = 
      [
        "clear-day",
        "clear-night",
        "partly-cloudy-day",
        "partly-cloudy-night",
        "cloudy",
        "rain",
        "sleet",
        "snow",
        "wind",
        "fog"
      ];
    for (i = 0; i < iconList.length; i++) 
     {   
       if(iconRequest == iconList[i])
       {
         icons.set("icon1", iconList[i]);
         icons.play();
       }//if
     }//for
var ftemp = result.currently.temperature;
var currentTemp = ftemp;
var ctemp = (ftemp - 32) / 1.8;
var isF = true;
//change temp
$("h2").on("click", function(temp){
  if(isF){
  
  $("h2").html(Math.round(ctemp) + "<a href=#>&deg;C</a>");
  
}//if
  else{
    
  $("h2").html(Math.round(ftemp) + "<a href=#>&deg;F</a>");
   
 }//else
   isF =! isF; //狀態取反
  
 });//onclick
  //change background
  var colors =
      ["#ffffcc",//yellow
     "#ccccff",//blue
     "#3c3c5d"//dark blue
      ];//backgroundColor

 
 
   if (ctemp >= 30)
   {
     $("html body").css("background-color","#ffffcc");
   }//if
   else if (ctemp < 20 )
   {   
     $("html body").css("background-color","#3c3c5d");      
   }//else if
   else 
   {
     $("body").css("background-color","#ccccff"); 
   }//else

 
    }// result
      
           );//getJSON
  

};//get weather



 
 


            
          
!
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.
Loading ..................

Console