cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <div id="fullpage">
  <div class="section" id="background">
    <div class="container-fluid">
      <div class=container>
        <div class=element>
          <div class="title">Your Local Weather
          </div> <!--title-->
          <div id="location">
          </div> <!--location-->
          <select class="form-control" id="temperatureSelect">
            <option>Celsius</option>
            <option>Fahrenheit</option>
          </select>
          <div id="current_temp">
          </div> <!--temperature-->
          <div id="max_and_min">
            <span id="temp_min"></span>, 
            <span id="temp_max"></span>
          </div> <!-- max_and_min -->
          <div id="main_condition">
          </div> <!--"main_condition"-->
          <img src="#" id="icon_condition"></img>
        </div> <!--element-->
      </div> <!--container-->
    </div> <!--container-fluid-->
  </div> <!--section-->
</div> <!--fullpage-->
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Lobster);

body {
  text-align: center;
  font-family: Georgia, Serif;
}

.container {
  display: table;  
}

.element {
  background-color:rgba(242,	242,	242, 0.8);
  display: inline-block;
  text-align: center;
  padding: 10px;
  vertical-align: middle;
  border-radius: 5%;
}

.title {
  font-family: Lobster;
  font-size: 300%;
  font-weight: 600;
  margin-bottom: 15px;
}

#location {
  font-size: 150%;
  margin-bottom: 20px;
}

#temperatureSelect, #max_and_min {
  margin-bottom: 20px;
}

#current_temp, #max_and_min {
  font-weight: 600;
  font-size: 150%;
}

#main_condition {
  font-family: Lobster;
  font-size: 300%;
  font-weight: 600;
}

            
          
!
            
              function displayInformation(city, state) {
  $("#location").text(city + ", " + state);
}

function kelvinToFahrenheit(temperature) {
  return (temperature * 9/5) - 459.67;
}

function kelvinToCelsius(temperature) {
  return temperature-273.15;
}

function displayTemperature(temperature, min, max) {
  var convert;
  var symbol = "";
  
  if ($("#temperatureSelect").val() === "Celsius") {
    convert = kelvinToCelsius;
    symbol = "°C";
  } else {
    convert = kelvinToFahrenheit;
    symbol = "°F";
  }  
  temperature = convert(temperature);
  min = convert(min);
  max = convert(max);
  
  $("#current_temp").text(Math.round(temperature) + " " + symbol);
  $("#temp_min").text("min: " + Math.round(min));
  $("#temp_max").text("max: " + Math.round(max));
}

function displayWeatherCondition(condition, icon) {
  console.log(icon);
  var weatherConditions = {
    "Clouds": "http://www.publicdomainpictures.net/pictures/40000/velka/fluffy-clouds.jpg", 
    "Rain": "http://www.publicdomainpictures.net/pictures/70000/velka/background-with-rain.jpg", 
    "Clear": "https://static.pexels.com/photos/3768/sky-sunny-clouds-cloudy.jpg",
    "Thunderstorm": "http://www.publicdomainpictures.net/pictures/100000/velka/desert-lightning-1408110525Yi1.jpg",
    "Drizzle": "http://www.publicdomainpictures.net/pictures/70000/velka/background-with-rain.jpg",
    "Snow": "http://www.publicdomainpictures.net/pictures/20000/velka/trees-in-the-snow-1321633816Vfq.jpg", 
    "Atmosphere": "https://upload.wikimedia.org/wikipedia/commons/c/ca/Dense_Seattle_Fog.jpg", 
    "Extreme": "https://upload.wikimedia.org/wikipedia/commons/9/9f/Pahoeoe_fountain_edit2.jpg", 
    "Additional": "https://upload.wikimedia.org/wikipedia/commons/6/6f/Katrina-noaaGOES12.jpg" 
  };
  
  
  $("#background").css("background-image", "url(" + weatherConditions[condition] + ")");
  $("#main_condition").text(condition);
  $("#icon_condition").attr("src", "http://openweathermap.org/img/w/" + icon + ".png")
  
}

function updatePage(weatherJsonData) {
  console.log(weatherJsonData);
  var data = weatherJsonData;
  displayInformation(data.name, data.sys.country);
  displayTemperature(data.main.temp, data.main.temp_min, data.main.temp_max);
  displayWeatherCondition(data.weather[0].main, data.weather[0].icon);
}

function ajaxError(error) {
  cosole.log("error ajax");
  alert(error);
}

function getWeather(latitude, longitude) {
  console.log(latitude +" "+longitude);
  
  $.ajax({
    url: "http://api.openweathermap.org/data/2.5/weather?lat=" + latitude + "&lon=" + longitude + "&appid=493d4ef79364d1fd1fff7de8ee150ad2",
    error: ajaxError,
    success: updatePage,    
  });
  
}

function runWhenCoordsReady(position) {
  console.log("in runWhenCoordsReady");
  var lat = position.coords.latitude;
  var lon = position.coords.longitude;
  getWeather(lat, lon);
}

function displayWeather() {
  console.log("in displayWeather");
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(runWhenCoordsReady);
  } else {
    $("html").css("background-color", "#f45942");
    $("html").text("Sorry, your browser does not support geolocation.");
  }
}

function main() {
  $('#fullpage').fullpage({
    anchors:['home-page'],
  });
  console.log("in main");
  
  displayWeather();
  
  $("#temperatureSelect").on("change", displayWeather);
}

$(document).ready(main);
            
          
!
999px
Loading ..................

Console