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.

            
                  <div class="row white-text z-depth-2 location">
      <div class="col s5 m4">
        <h5 class="left-align" id="place"></h5>
      </div>
      <div class="col s7 m8">
        <h5 class="right-align datetime" id="time">1:09 PM</h5>
        <h6 class="right-align datetime" id="day">Monday, May 30</h6>
      </div>
    </div>
    <div class="row hide-on-small-only valign-wrapper weather">
        <div class="col s12 m6 right-align icon-box"><i class="wi wi-day-cloudy" id="wi-l"></i></div>
        <div class="col s12 m6"><h5 class="white-text description"></h5></div>
    </div>
    <div class="row hide-on-med-and-up weather">
        <div class="col s12 center-align icon-box"><i class="wi wi-day-cloudy" id="wi-s"></i></div>
        <div class="col s12 center-align"><h5 class="white-text description"></h5></div>
    </div>
    <div class="row valign-wrapper">
      <div class="col s12 m12 center-align icon-box"  id="tempnow"></div>
    </div>
            
          
!
            
                    html {
        background: url(https://wallpapercave.com/wp/qQa5Pd7.jpg) no-repeat center center fixed grey;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
      }
      .location {
        background-color: rgba(0,0,0,0.75);
      }

      .datetime h5 {
        font-weight: bold !important;
      }
      .datetime h6 {
        font-weight: normal;
      }
      .icon-box {
          text-shadow: 0px 2px 2px rgba(0, 0, 0, 0.9);
      }
      i:hover {
        cursor: default;
      }

      @media (min-width: 601px) {
        #wi-l, #tempnow {
          font-size: 128px;
          color: white;
        }
        .description {
          font-size: 64px;
          text-shadow: 0px 2px 2px rgba(0, 0, 0, 0.9);
        }
        .weather {
          margin-top: 10%;

        }
      }

      @media (max-width: 600px) {
        #wi-s, #tempnow {
          font-size: 96px;
          color: white;
        }
        .description {
          font-size: 48px;
          text-shadow: 0px 2px 2px rgba(0, 0, 0, 0.9);
        }
        .weather {
          margin-top: 20%;
        }
        h5 {
          font-size: 1.44rem;
        }
        h6 {
          font-size: 0.8rem;
        }
      }
            
          
!
            
              var time = moment().format("h:mm A");
var day = moment().format("dddd, MMM D");
var temperature;
var dayicons = [
  { id: "01d", class: "wi wi-day-sunny" },
  { id: "02d", class: "wi wi-day-cloudy" },
  { id: "03d", class: "wi wi-day-cloudy" },
  { id: "04d", class: "wi wi-day-cloudy" },
  { id: "09d", class: "wi wi-day-showers" },
  { id: "10d", class: "wi wi-day-rain" },
  { id: "11d", class: "wi wi-day-thunderstorm" },
  { id: "13d", class: "wi wi-day-snow" },
  { id: "50d", class: "wi wi-day-fog" }
];
navigator.geolocation.getCurrentPosition(success, error);

function success(position) {
  var lat = position.coords.latitude;
  var lon = position.coords.longitude;
  var GEOCODING =
    "https://maps.googleapis.com/maps/api/geocode/json?latlng=" +
    lat +
    "%2C" +
    lon +
    "&language=en";

  $.getJSON(GEOCODING).done(function(location) {
    console.log(location);
    var address = location.results[2].formatted_address;
    $("#time").text(time);
    $("#day").text(day);
    $("#place").text(address);
    getWeather(lat, lon);
  });
}

function error(err) {
  console.log(err);
}

function getWeather(lat, lon) {
  var url =
    "https://api.openweathermap.org/data/2.5/weather?lat=" +
    lat +
    "&lon=" +
    lon +
    "&units=metric&cnt=7&lang=en&appid=753983d1101525edd0545786efa2b53d";
  $.getJSON(url, function(data) {
    console.log(data);
    var description = data["weather"][0]["description"];
    var icon = data["weather"][0]["icon"];
    temperature = Math.round(data["main"]["temp"]);
    var classtemp =
      '<i class="wi wi-celsius" id="unit" onclick="changeUnit(' +
      temperature +
      ')"></i>';
    $(".description").text(description);
    $("#tempnow").html(temperature + " " + classtemp);
    setIconClass(dayicons, icon);
  });
}

function setIconClass(array, icon) {
  for (i = 0; i < array.length; i++) {
    if (array[i]["id"] === icon) {
      $("#wi-l").attr("class", array[i]["class"]);
      $("#wi-s").attr("class", array[i]["class"]);
    }
  }
  return -1;
}
function changeUnit() {
  if ($("#unit").hasClass("wi wi-celsius")) {
    temperature = Math.round(temperature * 9 / 5 + 32);
    var classtemp =
      '<i class="wi wi-fahrenheit" id="unit" onclick="changeUnit()"></i>';
    $("#tempnow").html(temperature + " " + classtemp);
  } else {
    temperature = Math.round((temperature - 32) * 5 / 9);
    var classtemp =
      '<i class="wi wi-celsius" id="unit" onclick="changeUnit()"></i>';
    $("#tempnow").html(temperature + " " + classtemp);
  }
}
$(document).ready(function() {
  var clock = setInterval(function() {
    updateClock();
  }, 1000);
});

function updateClock() {
  time = moment().format("h:mm A");
  $("#time").text(time);
}

            
          
!
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