JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
<header>
<link href="https://fonts.googleapis.com/css?family=Acme" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Allan" rel="stylesheet" type="text/css">
</header>
<div class = "main-div">
<div class="text-center block">
<h1>Weather App</h1>
<img class = "text-center" src = "" id="weatherIcon">
<ul class = "text-center">
<li id="temp" class = "btn btn-default temp-class text-center"></li>
<br>
<li class = "btn btn-default text-center size-font" id="location"></li>
<br>
<li id="condition" class = "btn btn-default size-font"></li>
<li id="windSpeed" class = "btn btn-default size-font"></li>
</ul>
</div>
</div>
body {
background-image : url("https://images.unsplash.com/uploads/14122598319144c6eac10/5f8e7ade?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=tinysrgb&s=aa952e510c72aecebdaccc2a9c9f209d");
}
h1 {
font-family : Acme;
font-size : 5.0em;
color : white;
}
li {
font-family : Allan;
}
.block {
background-color:black;
opacity:.7;
padding:20px;
width : 50%;
margin-left:auto;
margin-right:auto;
border-radius : 10px;
vertical-align: middle;
}
.btn-default {
background-color:white;
border-color:black;
color:#337ab7;
font-size : 1.2em;
}
.main-div {
padding-top : 85px;
}
.temp-class {
font-size : 3.8em;
}
.size-font {
font-size : 2.2em;
}
$(document).ready(function() {
var long;
var lat;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
long = position.coords.longitude;
lat = position.coords.latitude;
var tempSwap = true;
var api =
"https://api.apixu.com/v1/current.json?key=c6c0bc019fc5480fb5b101241173004&q="+lat+", "+long;
$.getJSON(api, function(data) {
var country = data.location.country;
var region = data.location.region;
var location = data.location.name;
var tempC = data.current.temp_c;
var tempF = data.current.temp_f;
var condition = data.current.condition.text;
var windSpeed = data.current.wind_kph;
var weatherIcon = data.current.condition.icon;
$("#weatherIcon").attr("src", weatherIcon);
$("#location").html(location + ", " + region + ", " + country);
$("#condition").html(condition);
$("#windSpeed").html(windSpeed + " kmph");
$("#temp").html(tempC + "℃");
$("#temp").click(function() {
if (!tempSwap) {
$("#temp").html(tempC + "℃");
tempSwap = true;
} else {
$("#temp").html(tempF + "℉");
tempSwap = false;
}
});
if (condition === "Sunny")
$("body").css(
"background-image",
'url("https://cdn.cloudpix.co/images/sunny/sunny-day-wallpaper-weather-67eb048e101364cb35a5e03504acb949-large-533645.jpg")'
);
else if (condition === "Partly cloudy")
$("body").css(
"background-image",
'url("https://images.unsplash.com/uploads/14122598319144c6eac10/5f8e7ade?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=tinysrgb&s=aa952e510c72aecebdaccc2a9c9f209d")'
);
else if (condition === "Mist")
$("body").css(
"background-image",
'url("https://wallup.net/wp-content/uploads/2015/12/200858-sea-landscape-nature-mist.jpg")'
);
else if (condition === "Rainy" || condition === "Moderate or heavy rain with thunder")
$("body").css(
"background-image",
'url("http://wallpaper-gallery.net/images/rain-wallpapers/rain-wallpapers-20.jpg")'
);
});
});
}
});
Also see: Tab Triggers