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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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">
    <h1 id="city"></h1>
    <p id="temp"></p><h1><i id="weatherIcon"></i></h1>
      <p id="changeLoc" class="cL"><a>Change Location</a></p>
      <div class="form-group hider" id="zipUpdate">
        <input type="text" class="form-control" id="address" placeholder="Zip Code">
        <p class="help-block" id="update"><a>Update</a></p>
      </div>
    </div>
<!-- Modal -->
  <div class="modal fade" id="modal" role="dialog" tabindex="-1">
    <div class="modal-dialog modal-md">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <p class="modal-title">"Why isn't my location accurate?"</p>
        </div>
        <div class="modal-body">
          <h4>This site uses your public IP to make an estimate of your location. If you are using a mobile device, ad blocker, or VPN, this IP location may be innacurate. You can click change location to update your location manually. We default to Beverly Hills in cases where we can't retrieve IP information at all.</h4>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>
  </div>

 <div class="footer"><h6>Created by &nbsp;<a href="https://codepen.io/BobbyMcWho">Bobby McDonald</a></h6></div>
              
            
!

CSS

              
                
header{
  display:flex;
  align-items: flex-start;
}
html{
  height:100vh;
}
body {
  height: 100%;
  display:flex;
  flex-direction: row;
  justify-content:center;
  align-content:space-between;
  font-family:Oswald, arial,sans-serif;
  background:radial-gradient(circle at top,#263238,#455A64);
  color:#ffffff;
  user-select: none;
  flex-wrap:wrap;
}
.container{
  display:flex;
  flex-direction:column;
  align-items:center;
  width:100vw;
  align-self:stretch;
  margin-top:30vh;
}
p {
  margin:0;
  font-size:2em;
  user-select: none;
}

h1{
  font-size:3em;
  font-family: inherit;
  user-select: none;
  margin-top: 0;
}
@media screen and (max-width: 1000px) {
  h1{
    font-size:2em;
    font-family: inherit;
  }
  input{
    width: 30vw;
  }
}
p a {
  color:cyan;
  text-decoration:none;
  font-style:normal;
}
p a:hover {
  color:yellow;
  text-decoration:none;
  cursor: pointer;
}
h1 i {
  font-size: 2em;
  margin-bottom: .15em;
  margin-top: .25em;
}
.footer{
  align-self: stretch;
  font-family: Oswald,arial,sans-serif;
  font-style:normal;
  display:flex;
  align-content:flex-end;
}
.footer a{
  color:Orange;

}
.footer a:hover{
  color:Cyan;
  text-decoration: none;
}
input{
  color:black;
  width:10vw;
  text-align: center;

}
.cL{
  font-size:1em;
}
.cL a{
  color: #808080;
}
.cL a:hover{
  color: white;
}
.hider{
  display:none;
  flex-direction: column;
  align-items: center;
}
.fa { 
  vertical-align: top;
  font-size: .5em;
  color:#606060;
  font-style:normal;
}
.fa:hover { 
  vertical-align: top;
  font-size: .5em;
  color:#ffffff;
  text-decoration:none;
  cursor: pointer;
}
.modal-content{
  color:black;
}
.modal-content h4{
  color:black;
  font-style:normal;
}
a {
  font-style:normal;
}
              
            
!

JS

              
                $(document).ready(function() {
  // Set global variables
    var zip = "";
    var deg = "";
    var units = "imperial";
    var degs = 'F';
    var weatherStat;
    var cityName="";
    var timeDay, sunrise, sunset;
    var errorIP;
// Get visitor's zip code based on IP, and set it to the var zip
  function getIp()  {$.ajax({
        type: 'GET',
        format: 'jsonp',
        url: 'https://cors-anywhere.herokuapp.com/http://ip-api.com/json',
        success: function(data) {
            zip = data.zip;
            $('#address').attr('value',zip);
        },
    error: function(){ errorIP = true;zip = 90210;},
        complete: getTemp
    });}
    //Check for current units, and return appropriate abbreviation
    function degGet() {
      var checkUnits = units;
        if (checkUnits == 'imperial') {
            degs = 'F';
        } else if(checkUnits == 'metric'){
            degs = 'C';
        }
    }
    //Use Zip code to GET openweathermap JSON
    function getTemp() {
        $.ajax({
            type: 'GET',
            url: ('https://cors-anywhere.herokuapp.com/http://api.openweathermap.org/data/2.5/weather?zip=' + zip + ',us' + '&appid=2310fb952e694107d99d1667a348d72d&units=' + units),
            success: function(e) {
                weatherStat = e.weather[0].id;
                deg = Math.round(e.main.temp);
                cityName = e.name;
                sunrise = e.sys.sunrise;
                sunset = e.sys.sunset;
                timeDay = e.dt;
              fillTemp();
            },
            complete: function(){changeIcon();if(errorIP===true){$("#modal").modal();errorIP=false;}}
        });
    }
//Detect current units and convert temperature, rounded to 0 decimal places
function convert() {
  if (units == 'imperial'){
    deg = Math.round((deg * (9 / 5)) + 32,0);
    degGet();
    fillTemp();
  }
  else if (units == 'metric'){
    deg = Math.round(((deg - 32) * (5/9)),0);
    degGet();
    fillTemp();
  }
}
//Change units and run the convert function
    function changeU() {
      var unitCheck = units;
        if (unitCheck == 'imperial') {
            units = 'metric';
            convert();
        } else if (unitCheck == 'metric') {
            units = 'imperial';
            convert() ;
        }
    }
    //Function to call after the #units object has been created by fillTemp()
function setClick(){
  $('#units').click(changeU);
  $('#whyHere').click(function()
  {
    $('#modal').modal();
  });
                      }
//Insert html <a id="units"> into <p id="temp">
function fillTemp(){
  $('#temp').html(deg + "&#176;" + '<a id="units" >' + degs + '</a>');
  $('#city').html(cityName + '<a><i class="fa fa-question"id="whyHere"></i></a>');
  setClick();
}
//Change icon displayed based on value of weatherStat
function changeIcon(){
  var $weatherIcon = $('#weatherIcon');
  // if (timeDay >= sunrise && timeDay <= sunset){
  //   $weatherIcon.attr('class',"wi wi-owm-day-" + weatherStat);
  // }
  // else if (timeDay <= sunrise || timeDay >= sunset){
  //   $weatherIcon.attr('class',"wi wi-owm-night-" + weatherStat);}
  //   else
    {$weatherIcon.attr('class',"wi wi-owm-" + weatherStat)
    ;}
  // if (weatherStat == 'Thunderstorm'){
  //   $weatherIcon.attr('class',"wi wi-thunderstorm");
  // }
  // if (weatherStat == 'Drizzle' || 'Rain'){
  //   $weatherIcon.attr('class',"wi wi-showers");
  // }
  // if (weatherStat == 'Snow'){
  //   $weatherIcon.attr('class',"wi wi-snow");
  // }
  // if (weatherStat == 'Atmosphere'){
  //   $weatherIcon.attr('class',"wi wi-smoke");
  // }
  // if (weatherStat == 'Clear'){
  //   $weatherIcon.attr('class',"wi wi-wu-clear");
  // }
  // if (weatherStat == 'Extreme'){
  //   $weatherIcon.attr('class',"wi wi-windy");
  // }
}
//New Zip script
function updateWeather(){
 var  $address = $('#address');
  if ($address.val() !== '' || null){
    zip = $address.val();
  }
  zip=$('#address').val();
  getTemp();
  $('#zipUpdate').css('display','none');
  $('#changeLoc').css('display','');
}
//hide things
function peekaBoo(){
  $('#changeLoc').css('display','none');
  $('#zipUpdate').css('display','flex');
}
  $('#update').click(updateWeather);
  $('#changeLoc').click(peekaBoo);
  $('#address').keypress(function(e){
      if(e.keyCode==13 && $('#address').val() !==""){
        updateWeather();
      }});

  //prevent text highlighting on certain elements
    $('p, h1,#temp,#city').mousedown(function(event) {
        event.preventDefault();
   //Clear text input on click
      $("#address").click(function() {
    if (this.value !== "") {
        this.value = '';
    }
});
      //reinput
      $("#address").blur(function() {
    if (this.value === "") {
        this.value = zip;
    }
});
    });
  // initialize page
     getIp();
    getTemp();
});

              
            
!
999px

Console