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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <html lang="en">
<head>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>Sheep Weather App</title>
   <meta name="author" content="Top section graphics and turn mobile icon are designed by Freepik (http://www.freepik.com/), weather icons come from http://forecastfont.iconvau.lt/ (designed by https://twitter.com/alisisk). The Sheep Weather App is designed and coded by the doer.">
   <meta name="description" content="The project created during Free Code Camp course">
</head>
<body>
   <section class="top">  
         <div class="pull-right toggle">
            <label class="checkbox-inline">
              <input id="toggle" type="checkbox" checked data-toggle="toggle" data-on="Celsius" data-off="Fahrenheit" data-onstyle="info" data-offstyle="warning" data-style="toggle-pace">
            </label>
         </div>
   </section>
   
   <section class="middle">
      <div id="more-info-box" class="parent">
         <div class="cell text-center">
            <div id="wind">
               <p>Wind: <span></span></p>
            </div>
            <div id="humidity">
               <p>Humidity: <span></span></p>
            </div>
            <div id="description">
               <p>Weather Sheep says:<br/><span></span></p>
            </div>
         </div> <!-- cell -->
      </div>
   </section>

   <section class="bottom">
      <div id="more-btn" class="more" aria-labelledby="more weather information" tabindex="0">
         More
      </div> 
     
      
      <div class= "container-fluid">
         <div id="weather-box" class="info-box row hidden">
            <div id="data" class="col-xs-6 col-xs-offset-1 col-md-5 col-md-offset-1">
               <div id="city"></div>
               <div id="temperature">
                  <span id="number"></span>
               </div>
            </div> <!-- col weather details -->
            <div class="col-xs-5">
               <ul class = "weather-icon hidden" id="01d">
                  <li class = "icon-sun"></li>
               </ul>
               <ul class = "weather-icon hidden" id="01n">
                  <li class = "icon-moon"></li>
               </ul>
               <ul class = "weather-icon hidden" id="02d">
                  <li class = "basecloud"></li>
                  <li class = "icon-sunny"></li>
               </ul>
               <ul class = "weather-icon hidden" id="02n">
                   <li class = "basecloud"></li>
                  <li class = "icon-night"></li>
               </ul>
               <ul class = "weather-icon hidden" id="03d">
                  <li class = "basecloud"></li>
                  <li class = "icon-sunny"></li>
               </ul>
               <ul class = "weather-icon hidden" id="03n">
                  <li class = "basecloud"></li>
                  <li class = "icon-night"></li>
               </ul>
               <ul class = "weather-icon hidden" id="04d">
                  <li class = "icon-cloud"></li>
               </ul>
               <ul class = "weather-icon hidden" id="04n">
                  <li class = "icon-cloud"></li>
               </ul>
               <ul class = "weather-icon hidden" id="09d">
                  <li class = "basecloud"><li>
                  <li class = "icon-showers icon-sunny"></li>
               </ul>
               <ul class = "weather-icon hidden" id="09n">
                  <li class = "basecloud"><li>
                  <li class = "icon-showers icon-night"></li>
               </ul>
               <ul class = "weather-icon hidden" id="10d">
                  <li class = "basecloud"></li>
                  <li class = "icon-rainy"></li>
               </ul>
               <ul class = "weather-icon hidden" id="10n">
                  <li class = "basecloud"></li>
                  <li class = "icon-rainy icon-night"></li>
               </ul>
               <ul class = "weather-icon hidden" id="11d">
                  <li class = "basethundercloud"></li>
                  <li class = "icon-thunder"></li>
               </ul>
               <ul class = "weather-icon hidden" id="11n">
                  <li class = "basethundercloud"></li>
                  <li class = "icon-thunder icon-night"></li>
               </ul>
               <ul class = "weather-icon hidden" id="13d">
                  <li class = "basecloud"></li>
                  <li class = "icon-snowy"></li>
               </ul>
               <ul class = "weather-icon hidden" id="13n">
                  <li class = "basecloud"></li>
                  <li class = "icon-snowy icon-night"></li>
               </ul>
               <ul class = "weather-icon hidden" id="50d">
                  <li class = "icon-mist"></li>
               </ul>
               <ul class = "weather-icon hidden" id="50n">
                  <li class = "icon-mist"></li>
               </ul>
            </div> <!-- col weather icon -->
         </div> <!-- info-box details --->

         <div id="intro-text" class="info-box row">
            <div class="col-xs-12 text-center">
               <h1>Sheep Weather App</h1>
               <p class="thanks">Graphics by <a href="http://www.freepik.com/" target="_blank">Freepik</a> and <a href="https://twitter.com/alisisk" target="_blank">Ali Sisk</a></p>
            </div>
         </div> <!-- info box intro, default state before positoion set -->
      </div> <!-- container fluid -->
   </section> <!-- bottom section -->

   <section class="turn-around-mobile">
      <div class="text-center">
         <h2>Turn your phone vertically</h2>
      </div>
   </section>
</body>
</html>
              
            
!

CSS

              
                html {
   width: 100vw;
   height: 100vh;
}
body {
   width: 100%;
   height: 100%;
   background-color: lightblue;
   color: #455A64;
}
.top {
   height: 60vh;
   width: 100vw;
   background-image: url(http://theonewhodo.es/weatherapp-images/intro-screen.png);
   background-repeat: no-repeat;
   background-position: center center;
   background-size: cover;
}
/* top background sheep, day */
.top#top-01d {
   background-image: url(http://theonewhodo.es/weatherapp-images/01d.png);
}
.top#top-02d {
   background-image: url(http://theonewhodo.es/weatherapp-images/02d.png);
}
.top#top-03d {
   background-image: url(http://theonewhodo.es/weatherapp-images/03d.png);
}
.top#top-04d {
   background-image: url(http://theonewhodo.es/weatherapp-images/04d.png);
}
.top#top-09d {
   background-image: url(http://theonewhodo.es/weatherapp-images/09d.png);
}
.top#top-10d {
   background-image: url(http://theonewhodo.es/weatherapp-images/10d.png);
}
.top#top-11d {
   background-image: url(http://theonewhodo.es/weatherapp-images/11d.png);
}
.top#top-13d {
   background-image: url(http://theonewhodo.es/weatherapp-images/13d.png);
}
.top#top-50d {
   background-image: url(http://theonewhodo.es/weatherapp-images/50d.png);
}
/* top background sheep, night */
.top#top-01n {
   background-image: url(http://theonewhodo.es/weatherapp-images/01n.png);
}
.top#top-02n {
   background-image: url(http://theonewhodo.es/weatherapp-images/02n.png);
}
.top#top-03n {
   background-image: url(http://theonewhodo.es/weatherapp-images/03n.png);
}
.top#top-04n {
   background-image: url(http://theonewhodo.es/weatherapp-images/04n.png);
}
.top#top-09n {
   background-image: url(http://theonewhodo.es/weatherapp-images/09n.png);
}
.top#top-10n {
   background-image: url(http://theonewhodo.es/weatherapp-images/10n.png);
}
.top#top-11n {
   background-image: url(http://theonewhodo.es/weatherapp-images/11n.png);
}
.top#top-13n {
   background-image: url(http://theonewhodo.es/weatherapp-images/13n.png);
}
.top#top-50n {
   background-image: url(http://theonewhodo.es/weatherapp-images/50n.png);
}
/*extra cases*/
.top#top-windy {
   background-image: url(http://theonewhodo.es/weatherapp-images/sunny-sheep.jpg);
}
.top#top-cold {
   background-image: url(http://theonewhodo.es/weatherapp-images/sunny-sheep.jpg);
}
.top#top-hot {
   background-image: url(http://theonewhodo.es/weatherapp-images/sunny-sheep.jpg);
}
.top#top-calm {
   background-image: url(http://theonewhodo.es/weatherapp-images/sunny-sheep.jpg);
}
.bottom {
   height: 40vh;
   background-color: lightblue;
   color: #FFF;
   font-size: 1.5em;
}
.info-box {
   padding: 1.5em 0 0;
   font-size: 2em;
}
.toggle {
   margin: 1em 1em 0 0;
   visibility: hidden;
}
.toggle-pace .toggle-group { 
   transition: left 0.7s; -webkit-transition: left 0.4s; 
}
.weather-icon {
   font-size: 0.4em;
   margin: -10px 0 0;
   padding-left: 10px;
}
.weather-icon, .weather-icon li {
   margin-bottom: 5px;
}
.weather-icon li {
   list-style: none;
}
.icon-cloud::after {
   content: "\f106";
	color: #FFF;
}
.basecloud:before {
    content: '\f105';
    color: #FFF;
}
.turn-around-mobile {
   position: fixed;
   top: 0;
   bottom: 0;
   left: 0;
   right: 0;
   background: #fff;
   z-index: 1000;
   display: none;
   background: url(http://theonewhodo.es/weatherapp-images/mobile-vertical.png) no-repeat;
   background-position: center center;
}
.turn-around-mobile h2 {
   padding-top: 1em;
}
.more {
   background-color: pink;
   color: #FFF;
   width: 70px;
   height: 40px;
   position: absolute;
   left: 50%;
   margin: 0 0 0 -35px;
   border-radius: 0 0 10px 10px;
   text-align: center;
   border: 1px white dotted;
   cursor: pointer;
}
.extra-info .more {
   border-style: hidden dotted dotted dotted;
}
.middle {
   position: absolute;
   bottom: 40vh;
   left: 0;
   right: 0;
   height: 0;
   transition: height 0.5s;
   background-color: pink;
   border-radius: 20px 20px 0 0;
   overflow: hidden;
}
.extra-info .middle {
   height: 30vh;
   transition: height 1.5s;
}
/* vertical align center*/
.parent {
   display: table;
   height: 100%;
   width: 100%;
}
.cell {
   display: table-cell;
   vertical-align: middle;
   position: relative;
}
.middle p > * {
   font-weight: bold;
}
.thanks {
   padding-top: 1em;
   font-size: 12px;
}
#intro-text a {
   color: #FFECB3;
}

/* media queries */
@media screen and (min-width: 768px){
   .info-box {
      padding: 2em;
      font-size: 2.5em;
   }
   #data {
      text-align: right;
   }
   .more {
      font-size: 2em;
      width: 170px;
      height: 60px;
      margin-left: -85px;
   }
   .middle p {
      font-size: 1.8em;
   }
}

@media only screen and (max-height: 415px) and (orientation: landscape){
   .turn-around-mobile {
      display: block;
   }
   section:not(.turn-around-mobile) {
      display: none;
   }
}

@media screen and (max-width: 767px) {
   .info-box {
      font-size: 1.5em;
      text-align: left;
   }
   .middle p {
      font-size: 1.5em;
   }
}

@media screen and (min-width: 1200px) {
   .middle {
      width: 1000px;
      position: absolute;
      margin: 0 auto;
   }
}
              
            
!

JS

              
                var userPosition = null;
// origin of 3 next variables acting as constants http://openweathermap.org/weather-conditions
var COLD = 903;
var HOT = 904;
var CALM = 951;

function savePosition (position) {
   userPosition = position;
   getWeather(position.coords.latitude, position.coords.longitude, "metric");
}

function getWeather (lat, lon, units) {
   $.getJSON("https://procreative.eu/proxy/proxy.php?APPID=db4847852e5b0041310008ebb15c573a&units=" + units +"&lat=" + lat + "&lon=" + lon, function (result){
      $("#city").html(result.name);
      if (units=="metric") {
         $("#number").html((result.main.temp|0) + "° C");
      } else {
         $("#number").html((result.main.temp|0) + " F");
      }
      // setting more info
      if (units=="metric") {
         $("#wind span").html((result.wind.speed|0) + " meters/sec");
      } else {
         $("#wind span").html((result.wind.speed|0) + " miles/hour");
      }
      $("#humidity span").html((result.main.humidity|0) + "%");
      $("#description span").html(result.weather[0].description);
      // setting the icon
      $(".weather-icon").addClass("hidden");
      $(".weather-icon#" + result.weather[0].icon).removeClass("hidden");
      $("#weather-box").removeClass("hidden");
      $("#intro-text").addClass("hidden");
      // setting toggle ready
      $('.toggle').css('visibility', 'visible');
      // setting the top section background including situations without bottom section icons
      $(".top").attr("id", "top-" + result.weather[0].icon);
      
      if(result.weather[0].id >= 900 && result.weather[0].id !== COLD && result.weather[0].id !== HOT && result.weather[0].id !== CALM) {
         $(".top").attr("id", "top-windy");
      } else if (result.weather[0].id == COLD) {
         $(".top").attr("id", "top-cold");
      } else if (result.weather[0].id == HOT) {
         $(".top").attr("id", "top-hot");
      } else if (result.weather[0].id == CALM) {
         $(".top").attr("id", "top-calm");
      }
   });
}

function accessibleToggle(checkbox, ariaLabel) {
  var targetItem = checkbox.parent(".toggle.btn");
  targetItem.attr({
    "tabindex": 1,
    "aria-label": ariaLabel
  });
  targetItem.on("keyup", function(e) {
    //keyup in ASCII code == which
    if(e.which == 13) {
      checkbox.bootstrapToggle("toggle");  
    }
  });
}

// make more accessible without changing and restyling to a link
function moreBtn() {
   $("#more-btn").on("keyup", function(e) {
      if(e.which == 13) {
         $("#more-btn").trigger("click");
      }
   });
}


$(document).ready(function() {
   accessibleToggle($("#toggle"), "change measure");
   moreBtn();

   if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(savePosition, function(error) {
        // the message when geolocation cannot be read
        alert("Allow Geolocation On Your Device");
      }, {
        enableHighAccuracy: true,
        timeout : 5000
      });
   }
   $("#toggle").on("change", function(){
      if ($(this).prop("checked")) {
         getWeather (userPosition.coords.latitude, userPosition.coords.longitude, "metric"); 
      } else {
         getWeather (userPosition.coords.latitude, userPosition.coords.longitude, "imperial");
      }
   });
   $(".more").on("click", function (){
      $("body").toggleClass("extra-info");
      if($("body").hasClass("extra-info")){
         $(this).text("Less");
      } else {
         $(this).text("More");
      }
   });
}); 

              
            
!
999px

Console