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 id="weather"></div>
  <button class="js-geolocation" style="display: none;"> Use Location </button>
  <button class = "btn"> Toggle F/C </button>
<div id="license">
    <p> Rain Image: <a href= "https://flic.kr/p/dkssnD" >Fulmini su Monte Pellegrino </a> by <a href='https://www.flickr.com/photos/gerlos/'> Gerlos </a> is licensed under <a href='http://creativecommons.org/licenses/by/2.0/'> CC BY 2.0 </a> <br> 
    Clouds Image: <a href= "https://flic.kr/p/p7JuMr" >Clouds </a> by <a href='https://www.flickr.com/photos/tom_hall_nz/'> Tom Hall </a> is licensed under <a href='http://creativecommons.org/licenses/by/2.0/'> CC BY 2.0 </a> <br>
    All other images are property of myself, find my photos on my <a href= "https://www.flickr.com/photos/manuel_niederl"> flickr </a></p>
</div> 
            
          
!
            
              body {
  background:   url('https://i.imgur.com/KZoCXPV.jpg') no-repeat center center fixed; 
 background-size: cover;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover; 
  padding: 65px 25px;
}

#weather {
  width: 500px;
  margin: 0px auto;
  text-align: center;

}
#weather h2 {
  margin: 0 0 8px;
  color: #fff;
  font-size: 100px;
  font-weight: 400;
  text-align: center;
  text-shadow: 0px 1px 3px rgba(0, 0, 0, 0.15);
}

#weather li {
  background: #fff;
  background: rgba(255,255,255,255);
  padding: 10px;
  display: inline-block;
  border-radius: 10px;
}

#weather .currently {
  margin: 0 20px;
}
button {
  display: block; 
  margin: 15px auto;
  width: 100px;
  background: green;
  color: black;
  border: 0;
  border-radius: 5px;
  padding: -2px -2px -2px -2px;
}
 #license {
  position: fixed;
  right:0px;
   bottom:40px;
   height:30px;
   width:100%;
}
.btn {
  position: fixed;
  top: 20px;
  background: white;
  display: block;
  padding: 1px 1px 1px 1px; 
}
            
          
!
            
              var temp = 'c';
var setLocation = '';
var setWoeid = '';

if ("geolocation" in navigator) {
    $('.js-geolocation').show();
} else {
    $('.js-geolocation').hide();
}

$('.js-geolocation').on('click', function() {
    navigator.geolocation.getCurrentPosition(function(position) {
        loadWeather(position.coords.latitude + ',' + position.coords.longitude);
    });
});

loadWeather('Graz', ''); //@params location, woeid

function change() {
    if (temp == 'f') {
        temp = 'c';
    } else if (temp == 'c') {
        temp = 'f';
    }
	loadWeather();
}

$(".btn").on('click', function() {
    change();
});

function loadWeather(location, woeid) {
    if (location != undefined) {
        setLocation = location;
    }
    if (woeid != undefined) {
        setWoeid = woeid;
    }
    $.simpleWeather({
        location: setLocation,
        woeid: setLocation,
        unit: temp,
        success: function(weather) {
            html = '<h2>' + weather.temp + '&deg;' + weather.units.temp + '</h2>';
            html += '<ul><li>' + weather.city + ', ' + weather.region + ', ' + weather.country + '</li>';
            html += '<li class="currently">' + weather.currently + '</li>';
            $("#weather").html(html);

            //Backgrounds:
            if (weather.currently == 'Sunny' || weather.currently == "Fair (day)" || weather.currently == "Fair (night)" || weather.currently == "Hot") {
              $('body').css('background-image', 'url(https://i.imgur.com/cVTukTu.jpg)');
            } else {
              if (weather.currently == 'Mixed Snow And Sleet' || weather.currently == 'Mixed Rain And Snow' || weather.currently == 'Freezing Drizzle' || weather.currently == 'Snow Flurries' || weather.currently == 'Light Snow Showers' || weather.currently == 'Blowing Snow' || weather.currently == 'Snow' || weather.currently == 'Heavy Snow') {
                $('body').css('background-image', 'url(https://i.imgur.com/KZoCXPV.jpg)');
              } else {
                if (weather.currently == 'Showers' || weather.currently == 'Drizzle' || weather.currently == 'Hail' || weather.currently == 'Thunderstorms' || weather.currently == 'Severe Thunderstorms' || weather.currently == 'Mixed Rain and Hail' || weather.currently == 'Isolated Thunderstorms' || weather.currently == 'Scattered Thunderstorms' || weather.currently == 'Scattered Showers' || weather.currently == 'Thundershowers') {
                  $('body').css('background-image', 'url(https://i.imgur.com/AVV51lC.jpg)')
                } else {
                  if (weather.currently == 'Partly Cloudy (day)' || weather.currently == 'Partly Cloudy (night)' || weather.currently == 'Partly Cloudy' || weather.currently == 'Mostly Cloudy (night)' || weather.currently == 'Mostly Cloudy (day)' || weather.currently == 'Cloudy' || weather.currently == 'Smoke' || weather.currently == 'Mostly Cloudy' || weather.currently == 'Haze' )
                    $('body').css('background-image', 'url(https://i.imgur.com/o6FfluE.jpg)')
                }
              }
            }

          },
          error: function(error) {
            $("#weather").html('<p>' + error + '</p>');
          }
        });
      }
 
   
            
          
!
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