123

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!-- Live page available @ bit.ly/hf-localweather -->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Current Weather</title>

  <link rel="stylesheet" href="climacons/webfont/climacons-font.css">
  <link rel="stylesheet" href="font-awesome-4.7.0/css/font-awesome.min.css">

  <link rel="stylesheet" href="css/bootstrap.min.css">
  <link rel="stylesheet" href="css/style.css">

  <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
  <script type="text/javascript" src="js/bootstrap.min.js"></script>
  <script type="text/javascript" src="js/weather.js"></script>
  <!-- External Links
  # Bootstrap 3.3.7
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  # Font Awesome 4.7.0
  <link rel="stylesheet prefetch" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
  # Bootstrap 3.3.7 JS
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  # jQuery 3.2.1
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  # jQueryUI 1.11.2
  <script src="https//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
  -->
</head>

<body>
  <div id="data"></div>
  <div class="container">
    <div class="row">
      <div class="col-xs-12 col-md-10 col-md-offset-1" id="weatherSection">

        <!-- Main Header (City) -->
        <div class="row bg-light">
          <div class="col-xs-12" id="mainHeader">
            <div id="userLoc">
            </div>
          </div>
        </div>
        <!-- Main Current Condition Text -->
        <div class="row">
          <div class="col-xs-12">
            <div id="currentConditionText">
            </div>
          </div>
        </div>
        <!-- Main Current Condition Icon -->
        <div class="row">
          <div class="col-xs-12">
            <div id="currentConditionIcon">
            </div>
          </div>
        </div>
        <!-- Main Current Temp -->
        <div class="row">
          <div class="col-xs-12">
            <div id="currentTemp">
            </div>
          </div>
        </div>
        <button role="button" class="btn btn-default changeUnit">Change Unit</button>

        <!-- Current Info Header -->
        <div class="row">
          <div class="col-xs-12">
            <div class="textSmall smallHeader" id="currentHeader">
              Current
            </div>
          </div>
        </div>
        <!-- Current Info -->
        <div class="row bg-light">
          <div class="col-xs-6">
            <div class="textSmall infoLeft">
              Feels Like
            </div>
          </div>
          <div class="col-xs-6">
            <div class="textSmall infoRight" id="feelsLike">
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-xs-6">
            <div class="textSmall infoLeft">
              Humidity
            </div>
          </div>
          <div class="col-xs-6">
            <div class="textSmall infoRight" id="humidity">
            </div>
          </div>
        </div>
        <div class="row bg-light">
          <div class="col-xs-6">
            <div class="textSmall infoLeft">
              High
            </div>
          </div>
          <div class="col-xs-6">
            <div class="textSmall infoRight" id="maxTemp">
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-xs-6">
            <div class="textSmall infoLeft">
              Low
            </div>
          </div>
          <div class="col-xs-6">
            <div class="textSmall infoRight" id="minTemp">
            </div>
          </div>
        </div>
        <div class="row bg-light">
          <div class="col-xs-6">
            <div class="textSmall infoLeft">
              Wind Speed
            </div>
          </div>
          <div class="col-xs-6">
            <div class="textSmall infoRight" id="currentWindSpeed"></div>
          </div>
        </div>
        <div class="row">
          <div class="col-xs-6">
            <div class="textSmall infoLeft">
              Wind Direction
            </div>
          </div>
          <div class="col-xs-6">
            <div class="textSmall infoRight" id="currentWindDirection"></div>
          </div>
        </div>
        <div class="row bg-light">
          <div class="col-xs-6">
            <div class="textSmall infoLeft">
              Visibility
            </div>
          </div>
          <div class="col-xs-6">
            <div class="textSmall infoRight" id="visibility"></div>
          </div>
        </div>
        <!-- All Day Info -->
        <div class="row">
          <div class="col-xs-12">
            <div class="textSmall smallHeader">
              All Day
            </div>
          </div>
        </div>
        <div class="row bg-light">
          <div class="col-xs-6">
            <div class="textSmall infoLeft">
              Total Rain
            </div>
          </div>
          <div class="col-xs-6">
            <div class="textSmall infoRight" id="totalRain"></div>
          </div>
        </div>
        <div class="row">
          <div class="col-xs-6">
            <div class="textSmall infoLeft">
              Avg. Temp
            </div>
          </div>
          <div class="col-xs-6">
            <div class="textSmall infoRight" id="avgTemp"></div>
          </div>
        </div>
        <div class="row bg-light">
          <div class="col-xs-6">
            <div class="textSmall infoLeft">
              Avg. Humidity
            </div>
          </div>
          <div class="col-xs-6">
            <div class="textSmall infoRight" id="avgHumidity"></div>
          </div>
        </div>
        <div class="row">
          <div class="col-xs-6">
            <div class="textSmall infoLeft">
              Sunrise
            </div>
          </div>
          <div class="col-xs-6">
            <div class="textSmall infoRight" id="sunrise"></div>
          </div>
        </div>
        <div class="row bg-light">
          <div class="col-xs-6">
            <div class="textSmall infoLeft">
              Sunset
            </div>
          </div>
          <div class="col-xs-6">
            <div class="textSmall infoRight" id="sunset"></div>
          </div>
        </div>
        <div class="row">
          <div class="col-xs-6">
            <div class="textSmall infoLeft">
              Moonrise
            </div>
          </div>
          <div class="col-xs-6">
            <div class="textSmall infoRight" id="moonrise"></div>
          </div>
        </div>
        <div class="row bg-light">
          <div class="col-xs-6">
            <div class="textSmall infoLeft">
              Moonset
            </div>
          </div>
          <div class="col-xs-6">
            <div class="textSmall infoRight" id="moonset"></div>
          </div>
        </div>

        <footer class="credits">

          <span>Powered by</span><br/>
          <a href="http://adamwhitcroft.com/climacons/" target="_blank"><span class="climacon lightning sun climaLogo"></span>Climacons</a>
          <span>&nbsp;&amp;&nbsp;</span>
          <a href="http://apixu.com/" target="_blank">APIxu</a><br/>
          <span class="contact"><a href="https://github.com/harryrf" target="_blank">harryrf3</a> &copy; 2017</span>

        </footer>

      </div>
    </div>
  </div>

  <!--<script src="../js/bootstrap.min.js"></script>-->
  <!-- External Bootstrap 3.3.7 JS
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js "></script>
  -->

</body>

</html>
            
          
!
            
              /* Live page available @ bit.ly/hf-localweather */

body {
  color: aliceblue;
  background-color: #333;
  text-align: center;
  font-family: 'Lato', sans-serif;
  font-size: 100%;
}


/* Used for current view of forecast */

#weatherSection {
  background-color: #343434;
  box-shadow: 0px 0px 6px 3px rgba(0, 0, 0, 0.187);
}

#mainHeader {
  font-size: 3.5em;
  margin: 30px 0px;
}

#currentConditionText {
  font-size: 3.25em;
  margin-top: 15px;
}

#currentCondition {
  margin: 0;
}

#currentTemp {
  font-size: 12em;
}

.iconLarge {
  font-size: 30em;
  margin-top: -75px;
  margin-bottom: -75px;
}

.iconMedium {
  font-size: 20em;
  margin-bottom: -20px;
}

.textSmall {
  font-size: 1.60em;
  margin-top: 6px;
  margin-bottom: 6px;
}

.smallHeader {
  margin-top: 10px;
}

.infoLeft {
  text-align: left;
}

.infoRight {
  text-align: right;
}

.bg-light {
  border-top: 1px solid rgba(0, 0, 0, 0.187);
  border-bottom: 1px solid rgba(0, 0, 0, 0.187);
  background-color: rgba(69, 69, 69, 0.375);
}

footer {
  padding: 50px 0px;
}

.contact,
.credits {
  margin-top: 10px;
  text-align: center;
  font-size: 1.25em;
}

.contact a,
.credits a {
  text-decoration: none !important;
  color: #fff;
}

            
          
!
            
              // Live page available @ bit.ly/hf-localweather

$(document).ready(function() {

  $.ajax({
    url: "https://geoip-db.com/jsonp",
    jsonpCallback: "callback",
    dataType: "jsonp",
    success: function(location) {
      var city = location.city;
      var state = location.state;
      var country = location.country;
      var coords = location.latitude + ", " + location.longitude;

      // Location
      if (city === null && state !== null) {
        $("#userLoc").html(state);
      } else if (state === null) {
        $("#userLoc").html(country);
      } else {
        $("#userLoc").html(city);
      }

      // Live API
      api =
        "https://api.apixu.com/v1/forecast.json?key=49f97e05d5144c9c829185418170806&q=" +
        coords +
        "&days=3";

      // weather API
      $.getJSON(api, function(geo) {
        var location = geo.location;
        current = geo.current;
        condition = geo.current.condition;
        forecastday = geo.forecast.forecastday[0].day;
        astro = geo.forecast.forecastday[0].astro;
        is_day = geo.current.is_day;
        cCode = geo.current.condition.code;

        // check if is_day == 1 (day)
        // then check the conidition and set
        // icon based on the day conditions.
        // if is_day != (night) check conditions
        // then set icon based on night conditions.

        var icon = "";

        if (is_day == 1) {
          switch (true) {
            case cCode == 1000:
              icon = "climacon sun iconMedium";
              break;

            case cCode == 1003:
              icon = "climacon cloud sun iconMedium";
              break;

            case cCode == 1006:
              icon = "climacon cloud iconMedium";
              break;

            case cCode == 1009:
              icon = "climacon haze sun iconMedium";
              break;

            case cCode == 1030:
            case cCode == 1135:
              icon = "climacon fog sun iconMedium";
              break;

            case cCode == 1063:
            case cCode == 1180:
            case cCode == 1183:
            case cCode == 1240:
            case cCode == 1243:
              icon = "climacon rain sun iconMedium";
              break;

            case cCode == 1066:
            case cCode == 1210:
            case cCode == 1216:
            case cCode == 1222:
            case cCode == 1255:
            case cCode == 1258:
              icon = "climacon snow sun iconMedium";
              break;

            case cCode == 1069:
            case cCode == 1204:
            case cCode == 1207:
            case cCode == 1249:
            case cCode == 1252:
            case cCode == 1261:
            case cCode == 1264:
              icon = "climacon sleet sun iconMedium";
              break;

            case cCode == 1072:
            case cCode == 1198:
            case cCode == 1201:
              // needs climacon thermometer
              icon = "climacon rain iconMedium";
              break;

            case cCode == 1186:
            case cCode == 1189:
              icon = "climacon rain iconMedium";
              break;

            case cCode == 1087:
            case cCode == 1273:
              icon = "climacon lightning sun iconMedium";
              break;

            case cCode == 1279:
              // needs climacon snowflake
              icon = "climacon lightning sun iconMedium";
              break;

            case cCode == 1282:
              // needs climacon snowflake
              icon = "climacon lightning iconMedium";
              break;

            case cCode == 1114:
              // needs climacon wind
              icon = "climacon snow iconMedium";
              break;

            case cCode == 1117:
            case cCode == 1213:
            case cCode == 1219:
            case cCode == 1225:
              icon = "climacon snow iconMedium iconMedium";
              break;

            case cCode == 1147:
              // needs climacon thermometer
              icon = "climacon fog iconMedium";
              break;

            case cCode == 1150:
            case cCode == 1153:
              icon = "climacon drizzle sun iconMedium";
              break;

            case cCode == 1168:
            case cCode == 1171:
              // needs climacon thermometer
              icon = "climacon drizzle iconMedium";
              break;

            case cCode == 1192:
            case cCode == 1246:
              icon = "climacon downpour sun iconMedium";
              break;

            case cCode == 1195:
              icon = "climacon downpour iconMedium";
              break;

            case cCode == 1237:
              icon = "climacon sleet iconMedium";
              break;

            case cCode == 1276:
              icon = "climacon lightning iconMedium";
              break;
          }
        } else {
          switch (true) {
            case cCode == 1000:
              icon = "climacon moon iconLarge";
              break;

            case cCode == 1003:
              icon = "climacon cloud moon iconMedium";
              break;

            case cCode == 1006:
              icon = "climacon cloud iconMedium";
              break;

            case cCode == 1009:
              icon = "climacon haze moon iconMedium";
              break;

            case cCode == 1030:
            case cCode == 1135:
              icon = "climacon fog moon iconMedium";
              break;

            case cCode == 1063:
            case cCode == 1180:
            case cCode == 1183:
            case cCode == 1240:
            case cCode == 1243:
              icon = "climacon rain moon iconMedium";
              break;

            case cCode == 1066:
            case cCode == 1210:
            case cCode == 1216:
            case cCode == 1222:
            case cCode == 1255:
            case cCode == 1258:
              icon = "climacon snow moon iconMedium";
              break;

            case cCode == 1069:
            case cCode == 1204:
            case cCode == 1207:
            case cCode == 1249:
            case cCode == 1252:
            case cCode == 1261:
            case cCode == 1264:
              icon = "climacon sleet moon iconMedium";
              break;

            case cCode == 1072:
            case cCode == 1198:
            case cCode == 1201:
              // needs climacon thermometer
              icon = "climacon rain iconMedium";
              break;

            case cCode == 1186:
            case cCode == 1189:
              icon = "climacon rain iconMedium";
              break;

            case cCode == 1087:
            case cCode == 1273:
              icon = "climacon lightning moon iconMedium";
              break;

            case cCode == 1279:
              // needs climacon snowflake
              icon = "climacon lightning moon iconMedium";
              break;

            case cCode == 1282:
              // needs climacon snowflake
              icon = "climacon lightning iconMedium";
              break;

            case cCode == 1114:
              // needs climacon wind
              icon = "climacon snow iconMedium";
              break;

            case cCode == 1117:
            case cCode == 1213:
            case cCode == 1219:
            case cCode == 1225:
              icon = "climacon snow iconMedium";
              break;

            case cCode == 1147:
              // needs climacon thermometer
              icon = "climacon fog iconMedium";
              break;

            case cCode == 1150:
            case cCode == 1153:
              icon = "climacon drizzle moon iconMedium";
              break;

            case cCode == 1168:
            case cCode == 1171:
              // needs climacon thermometer
              icon = "climacon drizzle iconMedium";
              break;

            case cCode == 1192:
            case cCode == 1246:
              icon = "climacon downpour moon iconMedium";
              break;

            case cCode == 1195:
              icon = "climacon downpour iconMedium";
              break;

            case cCode == 1237:
              iconMedium;
              icon = "climacon sleet iconMedium";
              break;

            case cCode == 1276:
              icon = "climacon lightning iconMedium";
              break;
          }
        }

        // Current Condition Text and Icon

        $("#currentConditionText").html(condition.text);
        $("#currentConditionIcon").append("<div class='" + icon + "'></div>");

        // Switch for Fahrenheit and Celsius

        var fahrenheit = true;

        function changeUnit() {
          if (fahrenheit == true) {
            // current temp
            temp = Math.round(current.temp_f) + "&#8457;";
            // current info
            feelslike = Math.round(current.feelslike_f) + "&#8457;";
            maxtemp = Math.round(forecastday.maxtemp_f) + "&#8457;";
            mintemp = Math.round(forecastday.mintemp_f) + "&#8457;";
            wind = Math.round(current.wind_mph) + " MPH";
            vis = current.vis_miles + " MI";
            // forecasted current day
            avgtemp = Math.round(forecastday.avgtemp_f) + "&#8457;";
            maxwind = forecastday.maxwind_mph + " MPH";
            avgvis = forecastday.avgvis_miles + " MI";
            totalprecip = Math.round(forecastday.totalprecip_in) + " IN";

            fahrenheit = false;
          } else {
            // current temp
            temp = Math.round(current.temp_c) + "&#8451;";
            // current info
            feelslike = Math.round(current.feelslike_c) + "&#8451;";
            maxtemp = Math.round(forecastday.maxtemp_c) + "&#8451;";
            mintemp = Math.round(forecastday.mintemp_c) + "&#8451;";
            wind = Math.round(current.wind_kph) + " KPH";
            vis = current.vis_km + " KM";
            // forecasted current day
            avgtemp = Math.round(forecastday.avgtemp_c) + "&#8451;";
            maxwind = forecastday.maxwind_kph + " KPH";
            avgvis = forecastday.avgvis_km + " KM";
            totalprecip = Math.round(forecastday.totalprecip_mm / 100) + " CM";

            fahrenheit = true;
          }

          // Current Weather

          $("#currentTemp").html(temp);

          // Current Info

          $("#feelsLike").html(feelslike);
          $("#humidity").html(current.humidity + "&#37;");
          $("#maxTemp").html(maxtemp);
          $("#minTemp").html(mintemp);
          $("#currentWindSpeed").html(wind);
          $("#currentWindDirection").html(current.wind_dir);
          $("#visibility").html(vis);

          // Forecasted Current Day

          $("#totalRain").html(totalprecip);
          $("#avgTemp").html(avgtemp);
          $("#avgHumidity").html(forecastday.avghumidity + "&#37;");
          $("#maxWind").html(maxwind);
          $("#sunrise").html(astro.sunrise);
          $("#sunset").html(astro.sunset);
          $("#moonrise").html(astro.moonrise);
          $("#moonset").html(astro.moonset);
        } // end changeUnit();

        changeUnit();

        $(".changeUnit").on("click", function() {
          changeUnit();
        });
      }); // getJSON
    }
  });
}); // doc ready

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

Console