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 class='container-fluid'>
  <div class='jumbotron'>
    <!-- <button class='btn btn-danger' id='findMe'>Click for local weather update</button>
    <br><br>
    <p>OR</p>
    <form>Enter your location 
      <input type='text' name='Your Location'>
    </form>
    <br>-->
    <div class='row' id='info'>

      <div class='col-sm text-center' id= 'fordetail'>
        <span id='detail'></span>
        <img id='icon' alt='current portrayal'></img>
      </div>
      <div class='col-xs' id='temperature'>
      </div>
    </div>
  <div class='row'>
    <label class='switch'>
      <input type='checkbox'>
      <span class='slider'></span>
    </label>
  </div>
  </div>
<hr>
<footer>Thanks to <img src= 'https://icons.wxug.com/i/micro/weatherapp/logo-wu.jpg' width= '50px'> for the weather api <br>And I don't own the cgi's so thanks to all the original image owners for them too&#x1f44d;</footer>
</div>
            
          
!
            
              .container-fluid{
  position: relative;
  /*top:1em;*/  
}
.jumbotron{  padding : 0;margin: 0;
  background-repeat: no-repeat;
  background-size: cover;  
  
  /*max-width: 75%;
  margin: auto;*/
  height: 80vh;
  
  /*need to do the c to f and vice versa toggle next by learning css transition. after that, manual location entry*/
}
#info{
  background: white;
  opacity: 0.5;
  border-radius: .55em;
  /*margin : 1%;
  */padding: 1%;
  
  
}
#fordetail{
 /* margin: 0 auto;*/
  font-weight: bold;
  
}

.switch{
  background: black;
  width: 6em;
  height: 2em;
  cursor: pointer;
  opacity: 0.6;
  position: relative;
  margin: 0 auto;
  top: 1em;
  border-radius: 1em;
}

input{display: none;}

/*toggle code below*/
.slider:before{
  position: absolute;
  background-color: palegoldenrod;
  height: 1.5em;
  width: 2em;
  border-radius: 1em;
  margin: 4px;
  content: '\2103';/*for celsius symbol*/
  padding-left: 5px;
  opacity: .9;
  transition: transform .7s;
}
input:checked + .slider:before{
  transform: translateX(3.5em);
  content: '\2109'; /*for fahrenheit symbol*/
  padding-left: 5px;
}
footer{
  font-size: .75em;
  text-align: center;
}

            
          
!
            
              weatherFunc();
//var city, country, lat, lon, temp_c, temp_f, feelslike_F, weather;
function weatherFunc() {
  $.getJSON("https://ipapi.co/json/", json => {
    city = json.city;
    country = json.region;
    lat = json.latitude;
    lon = json.longitude;

    $.ajax({
      url:
        "https://api.wunderground.com/api/6927cbeace920251/geolookup/conditions/q/" +
        lat +
        "," +
        lon +
        ".json",
      dataType: "jsonp",
      success: function(parsed_json) {
        var location = parsed_json["location"]["city"];
        temp_c = parsed_json["current_observation"]["temp_c"];
        temp_f = parsed_json["current_observation"]["temp_f"];
        feels_likeC = parsed_json["current_observation"]["feelslike_c"];
        feels_likeF = parsed_json["current_observation"]["feelslike_f"];
        weather = parsed_json["current_observation"]["weather"];
        var icon_url = parsed_json["current_observation"]["icon_url"];
        //var icon = parsed_json['current_observation']['icon'];
        //console.log(weather);
        //alert("Current temperature in " + location + " is: " + temp_c + '. Feels like ' + feels_likeC + '. and it is ' + weather );
        $("#detail").html(
          "Current temperature in " +
            city +
            " is " +
            temp_c +
            "\xB0 C" +
            ". Feels like " +
            feels_likeC +
            "\xB0 C" +
            ". General condition: " +
            weather
        );

        $("#icon").attr("src", icon_url);
        //$('#background').css('background', 'url('+ imageLink + ')');
        var Rain =
          "http://78.media.tumblr.com/7d896a35c0df4e99156db17b59706ba5/tumblr_o9jr4r11gS1upvbufo1_400.gif";
        var Sunny =
          "http://files.57gif.com/webgif/0/1/7e/da0a46488ce4d1e7974bd2a47ac9b.gif";
        var Cloudy =
          "https://i.kinja-img.com/gawker-media/image/upload/t_original/1384296593722279313.gif";
        var Overcast =
          "https://media.giphy.com/media/3o7rc6sa2RvKo8K5EI/giphy.gif";
        var Clear = "https://media.giphy.com/media/l41lXD4w2wQC8hWg0/giphy.gif";
        var backgroundArr = ["Overcast", "Sunny", "Cloudy", "Clear", "Rain"];
        var backgroundArr2 = [Overcast, Sunny, Cloudy, Clear, Rain];
        var k = $("#detail").text();
        //console.log(k);
        //var re= new RegExp(weather, "g");
        /*    
    switch (weather){
     case 'Clear':
       $('.jumbotron').css('background', 'url(' + Clear + ')');       
       break;
     case 'Rain':
       $('.jumbotron').css('background', 'url(' + Rain + ')');
       break;
     case 'Cloudy':
       $('.jumbotron').css('background', 'url(' + Cloudy + ')');
       break;
     case 'Sunny':
       $('.jumbotron').css('background', 'url(' + Sunny + ')');
       break;
     default:
       $('.jumbotron').css('background', 'url(' + Sunny + ')');
   } 
   */
        //console.log(k.match(/backgroundArr[1]/gi));

        for (var i = 0; i < backgroundArr.length; i++) {
          //var arrElm = '"' + backgroundArr[i] + '"';
          //console.log(arrElm);
          //if(k.match(/re/gi)){
          if (k.match(new RegExp(backgroundArr[i], "g"))) {
            //console.log(backgroundArr[i]);
            //console.log("true");
            $(".jumbotron").css(
              "background-image",
              "url( " + backgroundArr2[i] + ")"
            );
          } else {
            console.log("false");
          }
        }
      }
    });
  });
}
function a(){
if (document.querySelector("input").checked) {
  $("#detail").html(
    "Current temperature in " +
      city +
      " is " +
      temp_f +
      "\xB0 F" +
      ". Feels like " +
      feels_likeF +
      "\xB0 F" +
      ". General condition: " +
      weather
  );
}
  else{
    $("#detail").html(
    "Current temperature in " +
      city +
      " is " +
      temp_c +
      "\xB0 C" +
      ". Feels like " +
      feels_likeC +
      "\xB0 C" +
      ". General condition: " +
      weather
  );
  }
}
document.querySelector('input').onchange=a;
/*
function weatherFunc() {
  var city, country, lat, lon;
  $.getJSON("https://ipapi.co/json/", json => {
    city = json.city;
    country = json.region;
    lat = json.latitude;
    lon = json.longitude;
    //$('#icon').text(lat);
    $.ajax({
      url:
        "https://api.wunderground.com/api/6927cbeace920251/conditions/q/" +
        lat +
        "," +
        lon +
        ".json",
      type: "GET",
      dataType: "jsonp",
      success: response => {
        //console.log(response);
        var location = response.current_observation.display_location.city;
        //console.log(location);
        var currCondition = response["current_observation"]["weather"];
        //console.log(currCondition);
        var degreeC = response.current_observation.temp_c;
        var degreeF = response.current_observation.temp_f;
        var logoLink = response.current_observation.image.url;
        var imageLink = response.current_observation.icon_url;

        console.log(imageLink);
        //$('#background').css('background', 'url('+ imageLink + ')');
        //$('#icon').html(weather);
        var rainy =
          "https://assets-auto.rbl.ms/4388606144d2f05020da2d1eb705336e37c521d5e3bad105e4b964fa13794b49";
        var sunny = "http://www.kinyu-z.net/data/wallpapers/78/975159.jpg";
        var cloudy =
          "https://pics.freeartbackgrounds.com/midle/Blue_Cloudy_Sky_Background-1074.jpg";
        var backgroundArr = [rainy, sunny, cloudy];
      }
    });
  });
}
*/

/*
$(document).ready(() => {
  var lat = "",
    lon = "";
  $("#findMe").click(() => {
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(showPosition);
      function showPosition(position) {
        // $('#temperature').html('longitude= ' + position.coords.longitude + '<br>latitude= '+ position.coords.latitude);
        lat = position.coords.latitude;
        lon = position.coords.longitude;
      }
      $.getJSON(
        "https://fcc-weather-api.glitch.me/api/current?lat=" +
          lat +
          "&lon=" +
          lon,
        json => {
          var weatherIcon = json.weather[0].icon;
          var description = json.weather[0].description;
          var temperature = json.main.temp;
           var celsius= (temperature-32) * 5/9;
          $("#temperature").html(description + " & " + Math.ceil(celsius));
        //  $("#icon").css("background-image", "url('"+weatherIcon+"')");
        }
      );
    } else {
      $("#temperature").html("Geolocation is not supported on your browser");
    }
  });
});
*/

            
          
!
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