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

              
                  <main>
    <div :class="display">
      <div class="frontFace">
        <h1 v-show="show">No GeoLocation</h1>
        <h3 v-show="show" v-html="noLocText"></h3>
        <input v-show="show" type="text" @keyup.enter="getWeather" v-model="position.city" placeholder="Type and hit enter">
      </div>
      <div class="backFace">
        <i :class="weatherIcons"></i>
        <h1>{{ weather }}</h1>
        <h2>{{ animateTemp }}{{ temp.unit }}</h2>
        <small @click="C2F">Fahrenheit <i class="wi wi-thermometer"></i> Celsius</small>
        <h4>The station is at: <strong>{{cityName}}, {{country}}</strong>.</h4>
      </div>
    </div>
  </main>
  <footer>
    <a href="https://twitter.com/spaniarddev" class="link">
      coded with <span class="love">&#9825;</span> by SpaniardDev
    </a>
  </footer>
              
            
!

CSS

              
                @import 'https://cdnjs.cloudflare.com/ajax/libs/weather-icons/2.0.9/css/weather-icons-wind.min.css';
@import 'https://cdnjs.cloudflare.com/ajax/libs/weather-icons/2.0.9/css/weather-icons.min.css';
@import 'https://cdnjs.cloudflare.com/ajax/libs/weather-icons/2.0.9/font/weathericons-regular-webfont.ttf';
@import 'https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300';

html {
  box-sizing : border-box;
}

*,
*:before,
*:after {
  box-sizing : border-box;
  box-sizing : inherit;
  margin     : 0;
  padding    : 0;
}

html,
body {
  width      : 100vw;
  height     : 100vh;
}

body {
  background      : url(https://www.dropbox.com/s/gbd8upnanqjj2z0/BG.jpeg?raw=1) no-repeat center center fixed;
  background-size : cover;
  display         : flex;
  flex-direction  : column;
  justify-content : center;
  align-items     : center;
  font-family     : 'Open Sans Condensed', sans-serif;
  font-size       : 16px;
  color           : #43545c;
  line-height     : 1.8rem;
}

main {
  position        : relative;
  height          : 70vh;
  /*min-height      : 450px;*/
  width           : 70vh;
  /*min-width       : 450px;*/
}

  .content {
    position        : absolute;
    background      : linear-gradient(
                      to bottom,
                      #ffffff 0%,
                      #ffffff00 100%
                    );
    border-radius   : 100%;
    border          : #43545c 1px solid;
    height          : 70vh;
    width           : 70vh;
    transform-style : preserve-3d;
    transition      : all 500ms ease;
  }

    .rotate {
      transform     : rotateY(180deg);
    }

  .frontFace {
    position            : absolute;
    display             : flex;
    flex-direction      : column;
    justify-content     : center;
    align-items         : center;
    width               : 100%;
    height              : 100%;
    backface-visibility : hidden;
  }

    .frontFace h1 {
      font-size       : 2.5rem;
      text-align      : center;
      text-decoration : underline;
    }

    .frontFace h3 {
      font-size   : 1.2rem;
      text-align  : center;
      padding     : 1.5rem 0 1rem 0;
    }
    
    main input[type="text"] {
      text-align    : center;
      border        : #43545c solid 1px;
      border-radius : 0.5rem;
      padding       : 0.5rem;
    }

  .backFace {
    position            : absolute;
    display             : flex;
    flex-direction      : column;
    justify-content     : center;
    align-items         : center;
    width               : 100%;
    height              : 100%;
    backface-visibility : hidden;
    transform           : rotateY(180deg);
  }

    .backFace i {
      font-size       : 5rem;
      margin-bottom   : 1rem;
    }

    .backFace h1 {
      font-size       : 1.5rem;
      margin-bottom   : 0.8rem;
    }

    .backFace h2 {
      font-size       : 2rem;
      margin-bottom   : 0.5rem;
    }

    .backFace small {
      font-size       : 1.2rem;
      padding         : 0.4rem 1rem;
      margin          : 0.8rem;
      cursor          : pointer;
      border          : #43545c 1px solid;
      border-radius   : 8px;
    }
      .backFace small:hover {
        background-color  : #43545c;
        color             : #ffffff;
      }
      .backFace small i.wi-thermometer {
        font-size       : 1.5rem;
        vertical-align  : middle;
        margin          : 0 0.2rem;
      }

footer {
  font-size     : 1rem;
  text-align    : center;
  padding-top   : 1.7rem;
}

  .love {
    color         : #d33333;
    font-size     : 1.3rem;
    vertical-align: middle;
  }

  footer a:link,
  footer a:visited {
    text-decoration : none;
    border-radius   : 100px;
    color           : #43545c;
  }

  footer a:hover {
    font-weight     : bold;
  }
              
            
!

JS

              
                /**
 *  Coded with ♥ by SpaniardDev
 * 
 *  Many things to polish, like:
 *  - The weird stuff going on when the virtual keyboard shows up on the phone.
 *  - Cross browser testing
 *  - Etc.
 * 
 */

new Vue( {
  el   : 'main',
  data : {
    position  : {
      lat     : 0,
      lon     : 0,
      acc     : 0,
      city    : '',
    },
    weather   : '',
    code      : 0,
    temp      : {
      kelvin  : 0.00,
      degrees : 0.00,
      unit    : 'ºC',
    },
    cityName  : '',
    country   : '',
    show      : false,
    display   : 'content',
    noLocText : `It seems we can't see your location.<br>Let's try and find your city.`,
  },
  // Tries to get the browser's location on start up.
  mounted ( ) {
    this.getLocation()
  },
  methods : {
    // Gets the browser's global position and iniciates the AJAX call. If it can't, sets a flag.
    getLocation ( ) {
      axios.get('https://ipapi.co/json').then( results => {
         
          this.position.lat = results.data.latitude,
          this.position.lon = results.data.longitude;
          //this.position.acc = results.coords.accuracy / 1000;
          this.getWeather( );        
      });
      
  
      const error = ( e ) => {
        if ( e.code === 1 ) console.error( 'PERMISSION DENIED'    );
        if ( e.code === 2 ) console.error( 'POSITION UNAVAILABLE' );
        if ( e.code === 3 ) console.error( 'TIME OUT'             );
        if ( e.code === 0 ) console.error( 'UNKNOWN ERROR'        );
        this.show = true;
      }
  
      const OPTIONS = {
        enableHighAccuracy  : true,
        timeout             : 5000,
        maximumAge          : 0
      };
  
      const position = navigator.geolocation.getCurrentPosition( success,error,OPTIONS );
    },
    // Establishes the AJAX call, fetches results and does the initial set up.
    getWeather ( ) {  
      const geoURL  = `//api.openweathermap.org/data/2.5/weather?lat=${this.position.lat}&lon=${this.position.lon}&appid=a7e8689c16bddca198ae1d762f5049cd`;
      const cityURL = `//api.openweathermap.org/data/2.5/weather?q=${this.position.city}&appid=a7e8689c16bddca198ae1d762f5049cd`;

      axios.get( this.show ? cityURL : geoURL )
      .then( results => {
        if( results.data.coord.lat == 0 && results.data.coord.lon == 0 ) {
          this.noLocText = `Sorry. The city you're trying to find was not found.<br>Try again with a differente name, please.`;
        } else {
          this.weather      = results.data.weather[0].main + ' (' + results.data.weather[0].description + ')';
          this.code         = results.data.weather[0].id;
          this.temp.kelvin  = ( results.data.main.temp ).toFixed( 1 );              // Kelvin
          this.temp.degrees = ( results.data.main.temp - 273.15 ).toFixed( 1 );     // K -> Celsius
          this.cityName     = results.data.name;
          this.country      = results.data.sys.country;
          this.display     += ' rotate';
          this.show         = false;
        }
      } )
      .catch( err => {
        this.noLocText = `Sorry. The city you're trying to find was not found.<br>Try again with a differente name, please.`;
      } );
    },
    // Changes from Celsius to Fahrenheit and viceversa. Also, animate their transitions.
    C2F ( ) { 
      if ( this.temp.unit == 'ºC' ) {
        const celsius = ( this.temp.kelvin * 9 / 5 - 459.67 ).toFixed( 1 );
        TweenLite.to( this.$data.temp, 0.5, { degrees : celsius });
        this.temp.unit    = 'ºF';
      } else {
        const fahrenheit = ( this.temp.kelvin - 273.15 ).toFixed( 1 );
        TweenLite.to( this.$data.temp, 0.5, { degrees : fahrenheit });
        this.temp.unit    = 'ºC';
      }
    }
  },
  computed: {
    // Animates the degrees between celsius and fahrenheit.
    animateTemp ( ) {
      return Number( this.temp.degrees ).toFixed( 1 );
    },
    // Chooses a Weather Icon for each weather ID.
    weatherIcons ( ) {
      if ( this.code >= 200 && this.code <= 232 )
        return 'wi wi-thunderstorm';
      else if ( this.code >= 300 && this.code <= 321 )
        return 'wi wi-rain-mix';
      else if ( this.code >= 500 && this.code <= 531 )
        return 'wi wi-rain';
      else if ( this.code >= 600 && this.code <= 622 )
        return 'wi wi-snowflake-cold';
      else if ( this.code >= 701 && this.code <= 781 )
        return 'wi wi-fog';
      else if ( this.code >= 801 && this.code <= 804 )
        return 'wi wi-cloudy';
      else if ( this.code == 800 )
        return 'wi wi-day-sunny';
    }
  }
} );
              
            
!
999px

Console