css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

            
              <body>
  <div class='container'>
    <div class="inner-container">
      <div class='city'></div>
      <div class='close'>
        <i class='ion-close-circled'></i>
      </div>
      <div class='country'></div>
      <div class='inside-stuff'>
        <div class='weather'></div>
        <div class='weather-icon'>
          <div class='weather-icon-container ion-ios-cloud'></div>
        </div>
        <div class='temperature'>
          <div class='temperature-text'>
           </div>
        </div>
      </div>
    </div>
    <div class="button">
      <i class="ion-ios-location"></i>
      <div class="button-bg"></div>
    </div>
    <div class="button-message">
      find your location
    </div>
    <div class="open-button">open</div>
  </div>
  <div class='bck'></div>
</body>
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Josefin+Sans:400,300,700);
@import url('https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css');

$font: 'Josefin Sans';
@mixin transition($val1,
$time,
$animate) {
  transition: $val1 $time $animate;
  -webkit-transition: $val1 $time $animate;
  -moz-transition: $val1 $time $animate;
  -o-transition: $val1 $time $animate;
  -ms--transition: $val1 $time $animate;
}

@mixin transform($transforms) {
  -moz-transform: $transforms;
  -o-transform: $transforms;
  -ms-transform: $transforms;
  -webkit-transform: $transforms;
  transform: $transforms;
}

@mixin center {
  top: 50%;
  left: 50%;
  @include transform(translate(-50%, -50%));
}

$backcolor: #0F1A20;
$backcolorlight: #334046;
body {
  font-family: $font;
  background: $backcolorlight;
}

.bck {
  z-index: -1;
  position: absolute;
  display: block;
  height: 100%;
  width: 100%;
  @include center;
  background: radial-gradient(#334046, $backcolor);
  background: -webkit-radial-gradient(#334046, $backcolor);
  background: -moz-radial-gradient(#334046, $backcolor);
  background: -o-radial-gradient(#334046, $backcolor);
  background: -ms-radial-gradient(#334046, $backcolor);
}

.container {
  color: black;
  @include center;
  position: absolute;
  display: block;
  height: 22em;
  width: 24em;
  background: none;
}

.inner-container {
  @include center;
  @include transition (display,
  1s,
  linear);
  overflow:hidden;
  border-radius: 15px;
  color: $backcolorlight;
  position: absolute;
  height: 100%;
  width: 100%;
  background: white;
  display: none;
  font-family: $font;
}

.city {
  width: 8em;
  font-size: 2.4em;
  position: absolute;
  top: 0.2em;
  left: 0.6em;
  font-weight: 300;
}
.close{
  display:block;
  float:right;
  font-size:1.6em;
  margin-right:0.3em;
  margin-top:0.2em;
  &:hover{
    color:#FB0531;
  }
}
.country {
  float: left;
  position: absolute;
  max-width: 18em;
  top: 3em;
  left: 1.6em;
  font-size: 1em;
}

.inside-stuff {
  position: absolute;
  display: block;
  top: 4.6em;
  border-color: #505050;
  border-top-style: solid;
  border-width: 5px;
  width: 90%;
  height: 16.5em;
  left: 50%;
  @include transform(translateX(-50%));
}

.weather {
  width:55%;
  position: relative;
  margin-top: 0.2em;
  font-size: 2em;
}

.weather-icon{
  height:0.8em;
  width:1.4em;
  display:block;
  position:relative;
  font-size:7em;
}
.weather-icon-container{
  position:absolute;
  top:50%;
  @include transform(translateY(-50%));
}
.temperature {
  display:block;
  width:55%;
  float:left;
  height:1.6em;
  position:relative;
  font-size:4em;
  font-weight:700;
  
  & :hover{
    @include transform(translateY(-50%) scale(1.2));
    color:$backcolor;
  }
  & .temperature-text{
    @include transition (color, 0.2s, linear);
    display:block; 
    width:100%;
    position:absolute;
    top:50%;
    @include transform (translateY(-50%));
  }
}

.button {
  @include transition (background,
  0.25s,
  linear);
  display: block;
  content: '';
  color: #FFFFFF;
  text-align: center;
  height: 1.3em;
  width: 1.3em;
  background: $backcolor;
  border-style: solid;
  border-width: 3px;
  border-color: #FFFFFF;
  border-radius: 50%;
  font-size: 6em;
  position: absolute;
  @include center;
  & i {
    z-index: 11;
    position: absolute;
    @include center;
  }
  &:hover {
    @include transform(translate(-50%, -50%) scale(1.1));
  }
}
.open-button{
  z-index:100;
  display:none;
  color:white;
  font-size:6em;
  font-weight:300;
  position:absolute;
  @include center;
  @include transition (all, 0.1s, ease-in);
  &:hover{
    @include transform(translate(-50%, -50%) scale(1.1));
    font-weight:400;
  }
}
.button-message {
  display: block;
  color: #FFF;
  text-align: center;
  height: 3em;
  width:10em;
  font-size: 2em;
  position: absolute;
  left: 50%;
  @include transform(translateX(-50%));
  top: 2em;
}

.bck {
  z-index: -1;
  width: 100%;
  height: 100%;
  position: absolute;
  display: block;
  @include center;
}

@keyframes pulse {
  0% {
    color: $backcolorlight;
  }
  100% {
    color: #FFF;
  }
}
.animate-pulse {
  animation: pulse 0.8s ease alternate infinite;
}
            
          
!
            
              //make sure you are using HTTPS for codepen
//to get the location
//weather font icons from the amazing IonIcons pack ---> http://ionicons.com/

//Hover over temperature to change units
//regexes to check the weather
var sunny = /(sun|clear|calm|hot)+/i;
var breeze = /breez+/i;
var storm = /(storm|tornado|hurricane)+/i;
var cloudy = /(cloud|fog|dust|haze|smok|bluster)+/i;
var part = /part+/i;
var rainy = /(rain|drizzl|shower)+/i;
var snowy = /(snow|freez|hail|cold)+/i;
var sleet = /sleet+/i;
//global weather variable so it's possible to check after ajax expires
var weather = null;

$(document).ready(function() {
  $(".open-button").hide();
  $(".inner-container").hide();
  $(".button").show();
  $(".button-message").show();
});

//weather icon replace according to regex match
var changeweather = function(w) {
  if (snowy.test(w)) {
    $('.weather-icon-container').addClass('ion-ios-snowy');
    return;
  } else if (sleet.test(w) || rainy.test(w)) {
    $('.weather-icon-container').addClass('ion-ios-rainy');
    return;
  } else if (storm.test(w)) {
    $('.weather-icon-container').addClass('ion-ios-thunderstorm');
    return;
  } else if (cloudy.test(w) || breeze.test(w)) {
    if (part.test(w)) {
      $('.weather-icon-container').addClass('ion-ios-partlysunny');
      return;
    } else {
      $('.weather-icon-container').addClass('ion-ios-cloud');
      return;
    }
  } else if (sunny.test(w)) {
    $('.weather-icon-container').addClass('ion-ios-sunny');
    return;
  }
}

//temperature conversion
$(".temperature").click(function() {
  var temp = $(".temperature-text").html();
  var unit = temp.slice(-1);
  var num = temp.slice(0, temp.length - 3) / 1;
  if (unit == "C") {
    num = Math.floor((num * 9) / 5 + 32);
    $(".temperature-text").html(num + " °F");
  } else {
    num = Math.floor((num - 32) * (5 / 9));
    $(".temperature-text").html(num + " °C");
  }
  console.log(num);
});

//close and open buttons
$(".close").click(function() {
  $(".inner-container").hide(200);
  $(".open-button").show();
});

$(".open-button").click(function() {
  $(".open-button").hide();
  $(".inner-container").show(200);
})

//location button hover animation
$(".button").hover(
  function() {
    $(".button").css({
      "background": "#FFFFFF",
      "color": "#0F1A20"
    });
  },
  function() {
    $(".button").css({
      "background": "#0F1A20",
      "color": "#FFFFFF"
    });
  });

//for when the the AJAX for weather api fetch starts
$(document).ajaxStart(function() {
  $(".button-message").html("fetching data");
});

//after weather data has been fetched, 
//change icon then show
//inner container
$(document).ajaxStop(function() {
  changeweather(weather);
  $(".inner-container").fadeIn(700);
  $(".button").hide();
  $(".button-message").hide();
});

//get coordinates
function place(callback) {
  var latitude = null,
    longitude = null;
  //for when location find is successful
  //return coordinates to a callback 
  //function 'callback'
  function success(position) {
    latitude = position.coords.latitude;
    longitude = position.coords.longitude;
    console.log(position.coords.latitude);
    callback([latitude, longitude]);
  };
  //for when location find is unsuccessful
  function error() {
    $(".button").removeClass("animate-pulse");
    $(".button").hover(
      function() {
        $(".button").css({
          "background": "#FFFFFF",
          "color": "#0F1A20"
        });
      },
      function() {
        $(".button").css({
          "background": "#0F1A20",
          "color": "#FFFFFF"
        });
      });
    $(".button-message").html("could not find location");
  }
  
  //call to api to find coordinates
  $(".button-message").html("locating");
  navigator.geolocation.getCurrentPosition(success, error);
}

//for finding location and only then 
//starting ajax for finding weather at
//specified location
$(".button").click(function() {
  $(".button").addClass("animate-pulse");
  $(".button").hover(function() {
    $(".button").css("background", "#FFFFFF");
  });
  $(".button").css({
    "background": "#FFFFFF",
    "color": "#334046"
  });

  place(
    function(coords) {
      $.ajax({
        url: 'https://simple-weather.p.mashape.com/weatherdata?lat=' + coords[0] + '&lng=' + coords[1],
        type: 'GET',
        dataType: 'json',

        success: function(data) {
          console.log(data);
          console.log(data.query.results.channel.item.condition.temp);
          var unit = data.query.results.channel.units.temperature;
          $(".country").html(data.query.results.channel.location.country);
          $(".city").html(data.query.results.channel.location.city);
          $(".weather").html(data.query.results.channel.item.condition.text);
          $(".temperature-text").html(data.query.results.channel.item.condition.temp + " °" + unit);
          weather = data.query.results.channel.item.condition.text;
        },
        error: function(err) {
          console.log(err);
          $('.inner-container').html('data for location does not exist');
        },
         beforeSend: function(xhr) {
          xhr.setRequestHeader("X-Mashape-Authorization", 'QNPeLrTuJImshsrV1xsmJKc5ytUZp16QOAAjsnch01iaEEZR3G');
        }
      });
    });
});
            
          
!
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.
Loading ..................

Console