A Pen by Connor Stricklan on CodePen.
Created
August 31, 2015 07:24
-
-
Save strickc/067e0e3c256f61b76c2c to your computer and use it in GitHub Desktop.
Weather Report
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="cds-fixed-bg cds-bg-warm"> | |
<div class="container center-text"> | |
<h1><span class="big-h">Fair-Weather Friend</span></h1> | |
<div class="col-xs-12"> | |
<span id="temp" class="cds-temp"></span> | |
<a id="temp-units" class="cds-temp-units" href="#" onclick="toggleUnits()"></a> | |
<span><img id="icon" class="cds-icon" href=""></span> | |
</div> | |
<div class="col-xs-4"> | |
<div class=" info-well"> | |
<span class="title">Your Location:</span> | |
<div class="weath-desc"> | |
<form> | |
<input id="location" class="form-control" type="text" id="location"> | |
</form> | |
</div> | |
</div> | |
</div> | |
<div class="col-xs-4"> | |
<div class=" info-well"><span class="title">Description:</span> | |
<div id="desc-string" class="weath-desc"></div> | |
</div> | |
</div> | |
<div class="col-xs-4"> | |
<div class=" info-well"> | |
<div class="title">Wind:</div> | |
<div id="wind-string" class="weath-desc"></div> | |
</div> | |
</div> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
getLocation(); | |
}); | |
var url="http://api.apixu.com/v1/current.json?key=a96e85d5c8b64ff79ae144410153008&q="; | |
var loc = document.getElementById("location"); | |
var temp = {}; | |
var bgClass = "cds-bg-warm"; | |
function getLocation() { | |
if (navigator.geolocation) { | |
navigator.geolocation.getCurrentPosition(showPosition); | |
} else { | |
loc.innerHTML = "Geolocation is not supported by this browser."; | |
} | |
} | |
function showPosition(position) { | |
console.log(position); | |
loc.value = "Detecting user location. . ."; | |
var locurl= url+position.coords.latitude + ", " + position.coords.longitude | |
$.get(locurl, setWeather); | |
} | |
function setWeather(weather){ | |
console.log(weather.location); | |
temp.c=weather.current.temp_c; | |
temp.f=weather.current.temp_f; | |
$("#location").val(getLoc(weather.location)); | |
$("#temp").text(weather.current.temp_c + "°"); | |
$("#temp-units").text("C"); | |
$("#icon").attr("src",weather.current.condition.icon) | |
$("#desc-string").text(weather.current.condition.text); | |
$("#wind-string").text(weather.current.wind_kph + " kph " + weather.current.wind_dir); | |
setBGforWeather(temp); | |
} | |
function getLoc(loc){ | |
console.log(loc); | |
if (loc.name) { | |
console.log(loc.name); | |
return loc.name + ", " + loc.region + " " + loc.country; | |
} else { | |
var name = loc.tz_id; | |
var i = name.search("/")+1; | |
name = name.substr(i).replace(/_/g," "); | |
return name; | |
} | |
} | |
function toggleUnits(){ | |
if ($("#temp-units").text() === "C"){ | |
$("#temp-units").text("F"); | |
$("#temp").text(temp.f + "°"); | |
} else { | |
$("#temp-units").text("C"); | |
$("#temp").text(temp.c + "°"); | |
} | |
$("#temp-units").blur(); | |
} | |
function setBGforWeather(temp){ | |
var thisClass = ""; | |
if (temp.f>=95){ | |
thisClass = "cds-bg-hot"; | |
} else if (temp.f>=65){ | |
thisClass = "cds-bg-warm"; | |
} else if (temp.f>=40){ | |
thisClass = "cds-bg-cool"; | |
} else { | |
thisClass = "cds-bg-cold"; | |
} | |
$(".cds-fixed-bg").removeClass(bgClass); | |
$(".cds-fixed-bg").addClass(thisClass); | |
bgClass = thisClass; | |
} | |
$("#location").keypress(function(e) { | |
if(e.which == 13) { | |
var locurl= url+$("#location").val(); | |
console.log(locurl); | |
$.get(locurl, setWeather); | |
return false; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body, | |
html, | |
main { | |
/* important */ | |
height: 100%; | |
} | |
body{ | |
color: #999999; | |
} | |
.center-text{ | |
text-align:center; | |
} | |
.cds-temp{ | |
font-size: 4em; | |
color: #111111; | |
} | |
.cds-temp-units{ | |
font-size: 3em; | |
color: #111111; | |
} | |
.cds-icon{ | |
margin-bottom:3em; | |
height: 6em; | |
} | |
.well{ | |
margin:0.5em; | |
} | |
.info-well{ | |
padding:0.2em; | |
background-color:#EEEEEE; | |
border:1px solid #AAAAAA; | |
border-radius:3px; | |
margin:0.5em; | |
} | |
.info-well>.title{ | |
display:block; | |
border-bottom:1px solid black; | |
} | |
.info-well>.weath-desc{ | |
display:block; | |
height:2em; | |
font-size:1.5em; | |
font-weight:bold; | |
padding-top:0.5em; | |
} | |
.cds-fixed-bg { | |
min-height: 100%; | |
background-size: cover; | |
background-repeat: no-repeat; | |
background-position: top center; | |
padding: 0px; | |
margin: 0px; | |
} | |
.cds-fixed-bg.cds-bg-hot { | |
background-image: url("http://i65.photobucket.com/albums/h235/Ignwar/Album%20Deserts/ThirstyDeathValleyCalifornia.jpg"); | |
} | |
.cds-fixed-bg.cds-bg-warm { | |
background-image: url("https://foodjules.files.wordpress.com/2013/01/spring-sunrise.jpg"); | |
} | |
.cds-fixed-bg.cds-bg-cool { | |
background-image: url("http://images.freeimages.com/images/previews/e92/autumn-landscape-transylvani-1515678.jpg"); | |
} | |
.cds-fixed-bg.cds-bg-cold { | |
background-image: url("http://images.freeimages.com/images/previews/67a/snow-forest-1389602.jpg"); | |
} | |
.big-h { | |
font-size: 2em; | |
font-family: Lobster, Monospace; | |
} | |
.sub-h { | |
margin-top:-50%; | |
font-size: 2em; | |
font-family: Lobster, Monospace; | |
} | |
#quote { | |
margin-top: 1em; | |
font-size:3em; | |
font-family: Lobster, Monospace; | |
} | |
#attrib { | |
text-align:right; | |
} | |
a.twitter-share-button, | |
a.twitter-mention-button, | |
a.twitter-hashtag-button { | |
display: inline-block; | |
margin-top:5em; | |
padding: 1px 3px 0 19px; | |
border: #ccc solid 1px; | |
border-radius: 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TEuNjk0QzY0LjgzOCwyMC4wNjgsNjcuMDU4LDE3Ljc2NSw2OC44MTIsMTUuMTQxeiIvPg0KPC9zdmc+DQo=") 2px 3px no-repeat, | |
linear-gradient(#fff, #dedede); | |
background-size: 16px 13px, auto auto; | |
/* Text */ | |
font: bold 11px/17px Helvetica, Arial, sans-serif; | |
text-decoration: none; | |
color: #333; | |
text-shadow: 0 1px 0 rgba(255, 255, 255, .5); | |
white-space: nowrap; | |
} | |
/* Color Highlight for keyboard navigation */ | |
a.twitter-share-button:focus, | |
a.twitter-mention-button:focus, | |
a.twitter-hashtag-button:focus { | |
outline: none; | |
border-color: #0089cb; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" /> | |
<link href="http://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment