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-fluid">
  <h1 id="changeMe" class="text-center">This Website shows you the weather</h1>
  <h2 id="gotCity" class="text-center">Getting city Data...</h2>
  <h3 id="theWeather" class="text-center">Getting Weather Data...</h3>
  <div class="text-center">
  <img id="weatherIcon" class="imgAttrb center-block" src="">
  </div>
   <br>
  <div class="text-center">
   <h5 class="tempBtn">°C</h5>
   <div>
   <div>
 
              
            
!

CSS

              
                body {
  background-color: #428bca;
  color: white;
}
#weatherIcon {
  display: none
}
#gotCity {
  display: none
}
#theWeather {
  display: none
}
.imgAttrb {
  height: 60px;
  width: 60px;
}
.tempBtn {
  color: 	#333eee;
}
.tempBtn:hover {
  font-size: 22px;
  cursor: pointer;
}
              
            
!

JS

              
                /*
  One of my earlier projects.
*/
$(document).ready(function() {
  var dateAndTime = new Date();

  //Makes sure there is only one interval initiated.
  var init = true;

  var temperature = "F";
   //Weather icon Data
    var weatherArr = [
      //DayTime Icons
      "https://s26.postimg.org/7e9df4tqx/Clear.png",
      "https://s26.postimg.org/hx06cthnd/Cloud.png",
      "https://s26.postimg.org/tampo0s61/Fog.png",
      "https://s26.postimg.org/gx9vh42hl/Haze.png",
      "https://s26.postimg.org/lkfxivpuh/Rain1.png",
      "https://s26.postimg.org/k6oankql5/Rain2.png",
      "https://s26.postimg.org/k82tuqhsp/Rain3.png",
      "https://s26.postimg.org/e8f2r2x09/Snow1.png",
      "https://s26.postimg.org/x20vo2v89/Snow2.png",
      "https://s26.postimg.org/rf4iqlspl/Snow3.png",
      "https://s26.postimg.org/5ihzq8fix/ThunderStorm.png",
      "https://s26.postimg.org/ep0adikrd/ThunderSnow.png"
    ];
    var nightWeatherArr = [
      //NightTime Icons
      "https://s26.postimg.org/x74mxr2jd/NightClear.png",
      "https://s26.postimg.org/dqjxb87fd/NightCloud.png",
      "https://s26.postimg.org/jsrk1pvvd/NightFog.png",
      "https://s26.postimg.org/z2rf8wrdl/NightHaze.png",
      "https://s26.postimg.org/jvg12aowp/NightRain1.png",
      "https://s26.postimg.org/qzxubbw61/NightRain2.png",
      "https://s26.postimg.org/5rk5twhp5/NightRain3.png",
      "https://s26.postimg.org/w158cp3mh/NightSnow1.png",
      "https://s26.postimg.org/5hcnak32x/NightSnow2.png",
      "https://s26.postimg.org/n8o9p0ihl/NightSnow3.png",
      "https://s26.postimg.org/cad06ttw9/NightThunderSnow.png",
      "https://s26.postimg.org/odibue4yh/NightThunderStorm.png"
    ];
  
  //Sets animation for icons given in the weatherArr array.
    function animateWeatherIcon(anim1, anim2, anim3) {
      $("#weatherIcon").attr("src", weatherArr[anim1]).fadeIn(1200);
      setTimeout(function() {
        $("#weatherIcon").attr("src", weatherArr[anim2]);
      }, 900);
      setTimeout(function() {
        $("#weatherIcon").attr("src", weatherArr[anim3]);
      }, 1900);
      setTimeout(function() {
        $("#weatherIcon").attr("src", weatherArr[anim1]);
      }, 2900);
    }
    //Sets animation for night icons given in the nightWeatherArr array.
    function animateNightWeatherIcon(anim1, anim2, anim3) {
      $("#weatherIcon").attr("src", nightWeatherArr[anim1]).fadeIn(1200);
      setTimeout(function() {
        $("#weatherIcon").attr("src", nightWeatherArr[anim2]);
      }, 900);
      setTimeout(function() {
        $("#weatherIcon").attr("src", nightWeatherArr[anim3]);
      }, 1900);
      setTimeout(function() {
        $("#weatherIcon").attr("src", nightWeatherArr[anim1]);
      }, 2900);
    }
  
  //Geolocation API Data
  $.getJSON("https://geoip.nekudo.com/api/js/json", function(myLocation) {
    console.log(myLocation);
   let locationLon = JSON.stringify(myLocation.location.longitude);
   let locationLat = JSON.stringify(myLocation.location.latitude);
   let locationCity = JSON.stringify(myLocation.city)
      .replace('"', "")
      .replace('"', "");
    
    //Get Weather API
     $.getJSON(
      "https://api.openweathermap.org/data/2.5/weather?lat=" +
        locationLat +
        "&lon=" +
        locationLon +
        "&APPID=15b1b15f60b546813423de628c378973&units=imperial",
      function(myWeather) {
        console.log(myWeather);
       let dataForcast = JSON.stringify(myWeather.weather[0].main);
        dataForcast = dataForcast.replace('"', "").replace('"', "");
       let dataWeather = JSON.stringify(myWeather.main.temp);
        dataWeather = Math.round(dataWeather);
   
        //Saves initial weather data for equation use.
       let savedWeather = dataWeather;
        
        $("#theWeather").text(
          dataForcast + " " + dataWeather + "°" + temperature
        ).fadeIn(800);
        $("#gotCity").text(locationCity).fadeIn(600);

        //Checks the time of day and changes the icons and the background color according to the time.
        if (dateAndTime.getHours() < 18 && dateAndTime.getHours() >= 7) {
          $("body").css({
            "background-color": "#428bca"
          });
          switch (dataForcast) {
            case "Clear":
              $("#weatherIcon").attr("src", weatherArr[0]).fadeIn(1200);
              break;
            case "Clouds":
              $("#weatherIcon").attr("src", weatherArr[1]).fadeIn(1200);
              break;
            case "Fog":
              $("#weatherIcon").attr("src", weatherArr[2]).fadeIn(1200);
              break;
            case "Haze":
              $("#weatherIcon").attr("src", weatherArr[3]).fadeIn(1200);
              break;
            case "Rain":
              if (init === true) {
                animateWeatherIcon(4, 5, 6);
                setInterval(function() {
                  animateWeatherIcon(4, 5, 6);
                  init = false;
                }, 3000);
              }
              break;
            case "Snow":
              if (init === true) {
                animateWeatherIcon(7, 8, 9);
                setInterval(function() {
                  animateWeatherIcon(7, 8, 9);
                  init = false;
                }, 3000);
              }
              break;
            case "Thunderstorm":
              $("#weatherIcon").attr("src", weatherArr[10]).fadeIn(1200);
              break;

            case "Thundersnow":
              $("#weatherIcon").attr("src", weatherArr[11]).fadeIn(1200);
              break;
            default:
              break;
          }
        }
        if (dateAndTime.getHours() >= 18 || dateAndTime.getHours() < 7) {
          //Checks the time of day and changes the icons and the background color according to the time.
          $("body").css({
            "background-color": "#172231"
          });
          //Night Icons
          switch (dataForcast) {
            case "Clear":
              $("#weatherIcon").attr("src", nightWeatherArr[0]).fadeIn(1200);
              break;
            case "Clouds":
              $("#weatherIcon").attr("src", nightWeatherArr[1]).fadeIn(1200);
              break;
            case "Fog":
              $("#weatherIcon").attr("src", nightWeatherArr[2]).fadeIn(1200);
              break;
            case "Haze":
              $("#weatherIcon").attr("src", nightWeatherArr[3]).fadeIn(1200);
              break;
            case "Rain":
              if (init === true) {
                animateNightWeatherIcon(4, 5, 6);
                setInterval(function() {
                  animateNightWeatherIcon(4, 5, 6);
                }, 3000);
                init = false;
              }
              break;
            case "Snow":
              if (init === true) {
                animateNightWeatherIcon(7, 8, 9);
                setInterval(function() {
                  animateNightWeatherIcon(7, 8, 9);
                }, 3000);
                init = false;
              }
              break;
            case "Thunderstorm":
              $("#weatherIcon").attr("src", nightWeatherArr[10]).fadeIn(1200);
              break;

            case "Thundersnow":
              $("#weatherIcon").attr("src", nightWeatherArr[11]).fadeIn(1200);
              break;

            default:
              break;
          }
        }
        //Sets temp to proper units and proper degrees and changes the color of the degrees button.
        $(".tempBtn").click(function() {
          if (temperature == "F") {
            dataWeather = Math.round((savedWeather - 32) * 5 / 9);
            $(".tempBtn").text("°" + temperature);
            temperature = "C";
            $("#theWeather").text(
              dataForcast + " " + dataWeather + "°" + temperature
            );
            $(".tempBtn").css({
              color: "#ff3333"
            });
          } else {
            dataWeather = savedWeather;
            $(".tempBtn").text("°" + temperature);
            temperature = "F";
            $("#theWeather").text(
              dataForcast + " " + dataWeather + "°" + temperature
            );
            $(".tempBtn").css({
              color: "#333eee"
            });
          }
        }); // temp click end
      }); // my weather callback function end
    }); // get geodata end
  }); // read end
              
            
!
999px

Console