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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <div class="container">
  <div class="title">
    <h1 id="city"></h1>
    <div id="graphic" class="weather-icon"></div>
    <div id="description" class='important-info text'></div>
    <div id="farenheit" class="temp-info"></div>
    <div id="celsius" class="temp-info"></div>
  </div>
</div>
<div class="description-container">
  <div class="block-1">
    <div class="text">
      <span>Max</span>
      <span id="max" class="important-info"> </span>
    </div>
    <div class="text">
      <span>Min</span>
    <span id="min" class='important-info'> </span>
    </div>
    
  </div>
  <div class="block-2">
    <div id="longitude" class=" text important-info">Lon: </div>
    <div id="latitude" class="text important-info">Lat: </div>
  </div>
  <div class="block-3">
    <div id="humidity" class="text important-info">Humidity: </div>
    <div id="pressure" class="text important-info">Pressure: </div>
    <div id="windSpeed" class="text important-info">Winds: </div>
  </div>
</div>

<div class="container-button">
      <div class="switch-button">
        <span class="active"></span>
        <button class="text switch-button-case left active-case">Celsius</button>
        <button class="text switch-button-case right">Farenheit</button>
      </div>
</div>

              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Space+Mono');
@import url('https://fonts.googleapis.com/css?family=Open+Sans:200,400,600,700,800');

body {
  height: 100%;
  background: #C95E67;
  /* fallback for old browsers */
}

h1 {
  font-family: 'Open Sans', Helvetica, sans-serif;
  font-size: 29px;
  color: #C95E67;
}

.text{
  font-family: 'Space Mono', Helvetica, sans-serif;
  font-size: 14px;
  color: #333;
}

.container {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  width: 100%;
  margin: 40px 0px 10px 0;
}

.container-button {
  display: grid;
  grid-template-columns: 1fr;
  margin-top: 10px;
}

.weather-icon,
.title{
  grid-column: 1/4;
  margin: 0 auto;
  text-align: center;
  background: #efefef;
  border-radius: 4px;
  padding: 15px 100px;
}

.important-info{ 
  grid-column: 1;
}

.description-container{
  background: #efefef;
  border-radius: 4px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  width: 450px;
  margin: 0 auto;
  padding:20px 0px;
}

.block-1 {
  grid-column: 1;
  padding: 10px;
}
.block-2{
  grid-column: 2;
  padding: 10px;
}
.block-3{
  grid-column: 3;
  padding: 10px;
}

.weatherInfo {
  height: 100%;
}

.temp-info {
  font-family: 'Open Sans', Helvetica, sans-serif;
  font-size: 65px;
  color: #C95E67;
  font-weight: 600;
}

.switch-button {
  grid-column: 1 1 1;
  border-radius: 4px;
  margin: 0 auto;
  width: 400px;
  height: 40px;
  text-align: center;
  position: relative;
  will-change: transform;
  z-index: 197 !important;
  cursor: pointer;
  -webkit-transition: .3s ease all;
  transition: .3s ease all;
  border: 1px solid #efefef;
  display: inline-block;
}

.switch-button-case {
  display: inline-block;
  background: none;
  width: 49%;
  height: 100%;
  color: #efefef;
  position: relative;
  border: none;
  -webkit-transition: .3s ease all;
  transition: .3s ease all;
  text-transform: uppercase;
  letter-spacing: 5px;
  padding-bottom: 1px;
}

.switch-button-case:hover {
  color: #151515;
  cursor: pointer;
}

.switch-button-case:focus {
  outline: none;
}

.active {
  position: absolute;
  color: #151515;
  background-color: #efefef;
  left: 0;
  top: 0;
  width: 50%;
  height: 100%;
  z-index: -1;
  -webkit-transition: .3s ease-out all;
  transition: .3s ease-out all;
}

.switch-button .active-case {
  color: #151515;
}

.signature {
  position: fixed;
  font-family: sans-serif;
  font-weight: 100;
  bottom: 10px;
  left: 0;
  letter-spacing: 4px;
  font-size: 10px;
  width: 100vw;
  text-align: center;
  color: #efefef;
  text-transform: uppercase;
  text-decoration: none;
}
              
            
!

JS

              
                // Get user's geolocation
var lat,
  lon,
  tWeather,
  icon,
  celsius,
  farenheit,
  iconNumber,
  minCelsius,
  maxCelsius,
  minF,
  maxF;

  
$.getJSON('https://ipapi.co/json/', function(data){
  console.log(data);


  // reaching the location API

console.log(data);
    // Finding the latitude and longitude, to be able to find the location
    $.each(data, function(k, v) {});
    lat = data.latitude;
    lon = data.longitude;

    $("#latitude").append(lat);
    $("#longitude").append(lon);

    $.getJSON("https://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&appid=059dcee9c15c93a942eb1f38b72876be", function(weatherData) {
      $.each(weatherData, function(j, b) {});
      console.log(weatherData);
      // fetch image and display weather and icon down below 
      tWeather = weatherData.main.temp;
      iconNumber = weatherData.weather[0].icon;

      icon = ("http://openweathermap.org/img/w/" + iconNumber + ".png");
      $("#graphic").append('<img src="' + icon + '"/>');

      $('#description').append(weatherData.weather[0].description);
      $('#city').append(weatherData.name);
      $("#windSpeed").append(weatherData.wind.speed + "km/h");
      $("#pressure").append(weatherData.main.pressure + "º");
      $("#humidity").append(weatherData.main.humidity + "%");
      minF = Math.floor(weatherData.main.temp_min * 9/5 - 459.67);
      maxF = Math.floor(weatherData.main.temp_max * 9/5 - 459.67);

      // translate Kelvin to Celsius
      celsius = Math.floor(weatherData.main.temp - 273.15);

      minCelsius = Math.floor(weatherData.main.temp_min - 273.15);
      maxCelsius = Math.floor(weatherData.main.temp_max - 273.15);
      // translate Kelvin to Farenhait T(K) × 9/5 - 459.67
      farenheit = Math.floor(weatherData.main.temp * 9 / 5 - 459.67);

      // display celsius by default 
      $('#celsius').append(celsius + 'ºC');
      $("#min").append( minCelsius + 'ºC');
      $("#max").append( maxCelsius + 'ºC');
    });
  

  // background code here 
});


var switchButton = document.querySelector('.switch-button');
var switchBtnRight = document.querySelector('.switch-button-case.right');
var switchBtnLeft = document.querySelector('.switch-button-case.left');
var activeSwitch = document.querySelector('.active');

function switchLeft() {
  switchBtnRight.classList.remove('active-case');
  switchBtnLeft.classList.add('active-case');
  activeSwitch.style.left = '0%';
  
  $('#farenheit').empty();
  $('#min').empty();
  $('#max').empty();
  $('#celsius').append(celsius + 'ºC');
  $("#min").append(minCelsius + 'ºC');
  $("#max").append(maxCelsius + 'ºC');
}

function switchRight() {
  switchBtnRight.classList.add('active-case');
  switchBtnLeft.classList.remove('active-case');
  activeSwitch.style.left = '50%';

  $('#celsius').empty();
  $('#min').empty();
  $('#max').empty();
  $('#farenheit').append(farenheit + 'ºF');
  $('#min').append(minF + "ºF");
  $('#max').append(maxF  + "ºF");

}

switchBtnLeft.addEventListener('click', function() {
  $('#celsius').empty();
  switchLeft();

}, false);

switchBtnRight.addEventListener('click', function() {
  $('#farenheit').empty();
  switchRight();

}, false);
              
            
!
999px

Console