cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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>
    <title>Local Weather App</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta charset="UTF-8">
    <script src="http://six03.com/weather/js/weather.js" defer></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" defer></script>
        <link rel="stylesheet" type="text/css" href="http://six03.com/weather/css/bootstrap.min.css">

    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
    <link href="https://fonts.googleapis.com/css?family=Racing+Sans+One|Open+Sans" rel="stylesheet">
  </head>
  <body>
    <div class="wrapper">
      <header>
        <h1>Your Local Weather</h2>
      </header>
      <section>
        <h2 id="city"></h2>
          <span>
            <h3 id="temp"></h2>
            <input id="convert" type="button" class="btn btn-lg btn-primary" value="&deg;F / &deg;C"/>
          </span>
        <div id="condition"></div>
        <div id="condition-icon"></div>
      </section>
      <footer>
        <p class="copyright">
          Copyright &copy; <script>document.write(new Date().getFullYear())</script>
        </p>
        <ul class="logos">
          <li><a href="https://twitter.com/toddlibby"><i class="fa fa-twitter fa-3x blue-text"></i></a></li>
          <li><a href="https://github.com/six03"><i class="fa fa-github fa-3x black-text"></i></a></li>
          <li><a href="https://www.freecodecamp.com/six03"><i class="fa fa-fire fa-3x green-text"></i></a></li>
          <li><a href="https://www.dribbble.com/six03"><i class="fa fa-dribbble fa-3x pink-text"></i></a></li>
        </ul>
      </footer>
    </div>
    
            
          
!
            
              html {
  box-sizing: border-box;
}
body {
  background-attachment: fixed;
  background-color: #222;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  color: #fff;
}
.wrapper {
  margin: 10em auto;
  width: 600px;
}
header h1 {
  text-align: center;
  font-family: 'Racing Sans One', cursive;
  font-size: 4em;
  color: #fff;
}
section,
#condition,
footer p {
  text-align: center;
  font-family: 'Open Sans', sans-serif;
  color: #fff;
}
#condition-icon {
  display: block;
  margin: 0 auto;
}
footer {
  height: 150px;
  text-align: center;
}
.logos {
  margin-right: 35px;
}
.logos li {
  list-style: none;
  display: inline;
}
.blue-text {
  color: #55acee;
}
.black-text {
  color: #000;
}
.green-text{
  color: #006400;
}
.pink-text {
  color: #ea4c89;
}
.copyright {
  font-family: 'Open Sans', sans-serif;
  margin-top: 2em;
}
h1, h2, h3, h4, h5, h6 {
  font-family: 'Racing Sans One', cursive;
}

            
          
!
            
              var tempC,tempF;

$(document).ready(function(){
       var locationUrl='http://ip-api.com/json';

       $.getJSON(locationUrl,function(json){
           fetchWeather(json.lat,json.lon);
       });

      function fetchWeather(lat,lon){
           var apiUrl="http://api.openweathermap.org/data/2.5/weather?lat="+lat+"&lon="+lon+"&appid=28a225d034047e360205e83cc640ce41";

           $.getJSON(apiUrl,function(json){
              tempC=parseInt(json.main.temp)-275;
              tempF=1.8*tempC+32;
              var condition=json.weather[0].main,
              wdescription=json.weather[0].description,
              wicon="http://openweathermap.org/img/w/"+json.weather[0].icon+".png",
              wid=json.weather[0].id,
              country=json.sys.country,
              city=json.name,
              backgroundId=[211,300,501,601,741,800,804],
              backgroundImg=[
                   "http://six03.com/weather/images/thunderstorm.jpeg",
                   "http://six03.com/weather/images/sprinkle.jpeg",
                   "http://six03.com/weather/images/rainy.jpeg",
                   "http://six03.com/weather/images/snowy.jpeg",
                   "http://six03.com/weather/images/foggy.jpeg",
                   "http://six03.com/weather/images/clear.jpeg",
                   "http://six03.com/weather/images/cloudy.jpeg",
                 ];
             backgroundId.push(wid);
             bgIndex=backgroundId.sort().indexOf(wid);
             $('body').css('background-image','url('+backgroundImg[bgIndex]+')');
             $('#city').text(city+" ,"+country);
             $('#temp').text(tempF.toString()+'° F');
             $('#condition').html("<h3>"+wdescription+"</h4>");
             $('#condition-icon').html("<img src="+wicon+">");
           });
         }
       });

$('#convert').click(function(){
   if($('#temp').text().indexOf('F')>-1){
      $('#temp').text(tempC.toFixed(1)+'° C')
   }
   else {
    $("#temp").text(tempF.toFixed(1)+'° F');
   }
  this.blur();
});

            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console